Ray Sun
Ray Sun

Reputation: 25

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. 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...

Upvotes: 0

Views: 207

Answers (2)

Hakuna Matata
Hakuna Matata

Reputation: 761

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

Upvotes: 2

Vivek Swansi
Vivek Swansi

Reputation: 419

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.

Upvotes: 0

Related Questions