Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最大只能开启16个线程,怎么解除限制?无法利用64核心 #481

Open
dignfei opened this issue Feb 14, 2023 · 5 comments
Open

Comments

@dignfei
Copy link

dignfei commented Feb 14, 2023

我的服务器是64核心的, 我有64个线程并发访问,但是只能跑满16个cpu,其他cpu全部空闲,怎么解决这个问题?

我找到了创建线程的代码,发现并没有限制线程数量:

private Executors() {
mService = java.util.concurrent.Executors.newCachedThreadPool();
mHandler = new Handler(Looper.getMainLooper());
}

@yanzhenjie
Copy link
Owner

嗯 你是指哪个线程池?是http服务的核心线程池?还是AndServer的服务?AndServer服务只需要一个线程就够了,主要是维持http传输的线程,这块代码不是你贴的这些。主要是要表达清楚你的诉求,为什么要跑满之类的,我可以改代码做支持。

@dignfei
Copy link
Author

dignfei commented Feb 25, 2023

嗯 你是指哪个线程池?是http服务的核心线程池?还是AndServer的服务?AndServer服务只需要一个线程就够了,主要是维持http传输的线程,这块代码不是你贴的这些。主要是要表达清楚你的诉求,为什么要跑满之类的,我可以改代码做支持。

谢谢大佬。最近出了事没有看。
我也不知道是http服务的核心线程池,还是AndServer的服务。
举例说明:
我开启了AndServer的服务。
然后其他程序通过网络访问这个http。比如访问 http://127.0.0.1/jisuan
`

@PostMapping(path = "/jisuan", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

String dktest(HttpRequest request, HttpResponse response, @RequestParam(name = "account") String account,

             @RequestParam(name = "password") String password) {

    Session session = request.getValidSession();

    session.setAttribute(LoginInterceptor.LOGIN_ATTRIBUTE, true);
    Cookie cookie = new Cookie("account", account + "=" + password);
    response.addCookie(cookie);
    // 执行一些耗cpu的运算,比如执行30秒的数学计算。
    //  data = 运算的结果;
    return "do successful:  "+data;
}

`
当有64个程序并发访问这个http://127.0.0.1/jisuan的时候,会发现只有前16个能成功连接,后面的48个无法连接上,只有等前面的16个执行完成之后,后面的才能连上,但是电脑有64核心,cpu并没有占满,只有16个核心使用率高,其他48个核心都空闲,可能AndServer只能开16个线程?我也不知道在哪里限制了线程数量。

为什么要跑满:因为每次访问http都需要执行我的代码计算10秒钟。当并发访问http://127.0.0.1/jisuan的时候,希望能利用上所有64个cpu,而不是只有16个核工作,其他核心都空闲的

@yanzhenjie
Copy link
Owner

明白了,我抽空搞搞。

@dignfei
Copy link
Author

dignfei commented Mar 3, 2023

明白了,我抽空搞搞。

静候老大的好消息

@zhangjibiao
Copy link

现在v2.1.11版本,我测试64个线程,都是能同时连接上AndServer的,用的Apche Jmeter工具测试的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants