英文:
How to set ThreadPoolTaskExecutor if sending numerous http requests at same time?
问题
在我的情况下,我需要向客户端应用发送超过一百万个HTTP请求,以弹出通知。如下伪代码所示:
int numOfHttpReq = 1000000;
for (int i = 0; i < numOfHttpReq; i++) {
使用ThreadPoolTaskExecutor调用异步方法...
}
我已经参考了这个网站上的文章,并得到了一个公式:
线程数 = 可用核心数 * (1 + 等待时间 / 服务时间)
然而,我认为这在我这种情况下并不完全适用。我想知道如何在这种情况下设置ThreadPoolTaskExecutor,例如CorePoolSize、MaxPoolSize、QueueCapacity等...
英文:
In my case, I need to send over million of http requests to client's app for popping notification. like below sudo code
int numOfHttpReq = 1000000;
for (int i = 0; i < numOfHttpReq; i++) {
call async method with ThreadPoolTaskExecutor ...
}
I have referenced article from this website, and obtain a formula
> Number of threads = Number of Available Cores * (1 + Wait time / Service time)
However, I think it's not 100% suitable in my case. I'd like to know how to set ThreadPoolTaskExecutor in this case such as CorePoolSize, MaxPoolSize, QueueCapacity, etc...
答案1
得分: 2
为什么不考虑使用“Gatling”工具进行这些性能相关的测试呢?您不需要担心对象池和其他内容,只需根据您的用例,在一段时间内有多少并发请求/并发用户/...以及其他选项。
Gatling
英文:
Why dont you take a look at the "Gatling" tool for these kind of performance related tests. You dont worry about the object pooling and other stuffs just feed then whats your use-case like within the span of time how many concurrent requests / concurrent users / ....other options as well there.
Gatling
答案2
得分: 0
你可以通过使用ThreadPoolExecutor提供的构造函数来很好地完成这个任务。
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
Executors.defaultThreadFactory(), defaultHandler);
}
然后,你可以使用工作线程来调用HttpRequest。
英文:
You can pretty well do this by simply using the constructor provided by ThreadPoolExecutor.
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
Executors.defaultThreadFactory(), defaultHandler);
}
And you can use worker thread to call the HttpRequest.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论