当我们每秒获得200个请求时,线程之间的资源没有任何依赖性。
我们目前正在使用以下代码
@Bean
public ThreadPoolTaskExecutor getTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
int maxPoolSize = 1;
if(Runtime.getRuntime().availableProcessors()-4>1){
maxPoolSize = Runtime.getRuntime().availableProcessors()-4;
}
taskExecutor.setMaxPoolSize(maxPoolSize);
System.out.println("Thread pool size SaveThread : "+taskExecutor.getMaxPoolSize());
taskExecutor.setDaemon(true);
taskExecutor.setThreadNamePrefix("SaveThread-");
taskExecutor.initialize();
return taskExecutor;
}
对于粗略估计,您可以考虑以下公式:
number_of_threads =(request_processing_time_ms / 1000)* number_of_request_to_handle
示例:您在30ms内处理请求。要处理200个请求/秒,您需要大约6个线程+一些缓冲区。
你还需要考虑:
最好的方法是设置从其他机器执行的性能测试,而不是运行软件。