Java确定最佳线程数的最佳方法 [英] Java best way to determine the optimal number of threads

查看:79
本文介绍了Java确定最佳线程数的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个爬网程序,该爬网程序具有一组处理Web IO并处理每个网页的辅助线程.但是,我不确定如何找到系统的最佳线程数.监视线程性能并具体测量抖动等因素的最佳方法是什么?

I am writing a crawler which have a set number of worker threads that handle web IO and process each webpage. However, I am not sure how I can find the optimal number of threads for the system. What's the best way to monitor thread performance and concretely measure factors such as thrashing?

推荐答案

只需运行基准测试.您可以通过让线程定期向线程管理器报告其吞吐量来动态地执行此操作.管理器可以操纵线程数以探查性能如何随线程数变化并确定接近最佳的值.它也可以偶尔决定尝试看看是否可以找到一个新的最优值. (最佳数量可能会随环境条件的变化而变化,例如其他进程的总体CPU负载.)

Just run benchmarks. You can do this dynamically by having threads report their throughput on a periodic basis to a thread manager. The manager can manipulate the thread count to probe how the performance varies with thread count and settle on a near-optimal value. It can also occasionally decide to experiment to see if a new optimal can be found. (The optimal count may vary with varying environmental conditions like overall CPU load from other processes.)

这篇关于Java确定最佳线程数的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆