我在具有四核CPU的机器上运行Ubuntu.我编写了一些测试Java代码,它产生了一定数量的进程,这些进程只是在运行时为一定数量的迭代增加一个volatile变量.
我希望运行时间不会显着增加,而线程数小于或等于内核数量,即4.实际上,这些是我从UNIX time命令使用"实时"的时间:
1个线程:1.005s
2个主题:1.018s
3个主题:1.528s
4个主题:1.982s
5个主题:2.479s
6个主题:2.934s
7个主题:3.356s
8个主题:3.793s
这表明添加一个额外的线程不会像预期的那样增加时间,但随后时间会增加3和4个线程.
起初我以为这可能是因为操作系统阻止了JVM使用所有内核,但我跑了top,它清楚地表明,有3个线程,3个内核运行在~100%,有4个线程,4个内核是超出.
我的问题是:为什么在3/4 CPU上运行的代码与在1/2运行时的速度大致相同?因为它是在所有核心并行运行.
这是我的主要参考方法:
class Example implements Runnable {
// using this so the compiler does not optimise the computation away
volatile int temp;
void delay(int arg) {
for (int i = 0; i < arg; i++) {
for (int j = 0; j < 1000000; j++) {
this.temp += i + j;
}
}
}
int arg;
int result;
Example(int …Run Code Online (Sandbox Code Playgroud) 当我尝试运行服务器时,EventMachine::run我不断收到错误消息,说明该端口正在使用中.自从我使用命令在后台运行服务器以来,这开始了nohup.
我很确定我已经杀了我开始的过程:
ps,并将其杀死.它不再出现了.lsof -i :8081(8081是我运行它的端口),没有任何显示.我也认为可能是我缺乏root用户,所以尝试root作为无效.
我也重新启动了服务器.
如果还有什么我可以尝试,请告诉我.
注意:这是关于debian的.
我正在使用 elixir_talk 库。连接后,我想在连接到 beanstalkd 后调用私有函数。我刚刚添加了 typespecs 并运行了 Dialyzer(通过dialyxir)。我收到错误:
my_module.ex:3: The specification for 'Elixir.MyModule':f/0 states that the function might also return 'ok' | {'error',_} but the inferred return is none()
my_module.ex:4: Function f/0 has no local return
my_module.ex:14: Function g/1 will never be called
Run Code Online (Sandbox Code Playgroud)
我能找到的产生这个的最小例子是
defmodule MyModule do
@spec f() :: :ok | {:error, term}
def f() do
case ElixirTalk.connect('127.0.0.1', 11300) do
{:ok, conn} ->
g(conn)
{:error, err} ->
{:error, err}
end
end
@spec g(pid) :: :ok
defp g(pid) do
:ok …Run Code Online (Sandbox Code Playgroud) 我正在使用Eclipse和PyDev在Python中编写一个编译器.我来到了一个需要用Java编写代码的阶段.如果有一种方法可以将这些组合到一个项目中,我就会徘徊,因为目前我有两个独立的项目,每当我需要更改Java代码时,我必须手动将.class文件复制到Python项目中.
如果这是不可能的,那么您建议的是构建这些项目文件的最优雅方式,以及如何设置构建过程?
谢谢.
我目前正在Haskell中使用ADT并尝试构建ADT Figure:
data Figure = Rect { x :: Integer, y :: Integer, width :: Integer, height :: Integer}
| Circle { x :: Integer, y :: Integer, radius :: Integer}
| CombiFigure Figure Figure
deriving (Eq, Show, Read)
Run Code Online (Sandbox Code Playgroud)
现在我遇到了一个问题,即如何实现一个不应该接受每个函数的函数,Figure例如只有一个函数Circle.
我的设计已经不好了吗?或者有一些最佳实践如何做到这一点?
例如,考虑直径函数.我想到的一切(我是Haskell的初学者)是以下两个选项,使用undefined或Maybe:
1:
diameter :: Figure -> Integer
diameter (Circle _ _ r) = 2 * r
diameter _ = undefined
Run Code Online (Sandbox Code Playgroud)
2:
diameter :: Figure -> Maybe Integer
diameter (Circle _ …Run Code Online (Sandbox Code Playgroud) haskell pattern-matching algebraic-data-types maybe undefined-function
我是PHP,Javascript,jQuery等新手,所以我发现这很令人困惑.
我写了一个与JSON代码相呼应的php文件.然后我尝试将此响应存储到客户端上的Javascript变量中,如下所示:
var res;
$.getJSON("my_php_file", { some_param: "param" },
function(data) {
res = data;
}
});
Run Code Online (Sandbox Code Playgroud)
相反,Web浏览器只是在当前窗口中打开响应JSON,而不是将结果保存到res.为什么是这样?
谢谢