[英]How to set ThreadPoolTaskExecutor if sending numerous http requests at same time?
In my case, I need to send over million of http requests to client's app for popping notification.就我而言,我需要向客户端的应用程序发送超过百万个 http 请求以弹出通知。 like below sudo code
就像下面的 sudo 代码
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)
线程数 = 可用内核数 * (1 + 等待时间 / 服务时间)
However, I think it's not 100% suitable in my case.但是,我认为它不是 100% 适合我的情况。 I'd like to know how to set ThreadPoolTaskExecutor in this case such as CorePoolSize, MaxPoolSize, QueueCapacity, etc...
我想知道在这种情况下如何设置 ThreadPoolTaskExecutor,例如 CorePoolSize、MaxPoolSize、QueueCapacity 等...
Why dont you take a look at the "Gatling" tool for these kind of performance related tests.你为什么不看看这些性能相关测试的“Gatling”工具。 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
加特林
You can pretty well do this by simply using the constructor provided by ThreadPoolExecutor.您只需使用 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.并且您可以使用工作线程来调用 HttpRequest。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.