0

All

I want to use HttpClient4 to do our RESTful API stress testing by concurrently send request to target server , Can I use one HttpClient instance ?

CloseableHttpClient httpclient = HttpClients.createDefault();

whether it must let each concurrent thread to new different HttpClient instance ?

How to improve design to reduce client instance resource but keep the same concurrent number , such let 200 thread send each request concurrently .

Use PoolingHttpClientConnectionManager it seems always can't concurrently execute .

Jerry Cai
  • 571
  • 2
  • 8
  • 18
  • But My question is How to let each thread concurrently send http request ? If I have 100 threads to start send http request with the same one httpClient instance , It will be OK? or each threads must new thread-based instance to send  ? – Jerry Cai Oct 14 '13 at 08:35

3 Answers3

1

Can I use one HttpClient instance ?

It's perfectly ok to share single HttpClient instance between multiple threads. You may even have a single instance for the whole application.

Use PoolingHttpClientConnectionManager it seems always can't concurrently execute.

PoolingHttpClientConnectionManager is capable of concurrent request execution. May be you need to enlarge pool size using setDefaultMaxPerRoute(...) and setMaxTotal(...). See my answer here for the detailed description of how to use these settings.

To get more precise answer consider posting an SSCCE.

Community
  • 1
  • 1
Jk1
  • 11,233
  • 9
  • 54
  • 64
  • But My question is How to let each thread concurrently send http request ? If I have 100 threads to start send http request with the same one httpClient instance , It will be OK? or each threads must new thread-based instance to send  ? – Jerry Cai Oct 14 '13 at 08:36
  • It's OK, you can use the same HttpClient instance for all your threads – Jk1 Oct 14 '13 at 08:45
  • But one thread close httpclient , can another thread use it again ? – Jerry Cai Oct 14 '13 at 08:54
  • In this case threads should not close() shared client instance – Jk1 Oct 14 '13 at 09:10
0

You can do it, but you need pc with a lot of thread. because even if you write in your code a bilion Threads, you can't tun it on your processor, because your processor have limit of core, and in same time work only X number of threads, where x core number in proccesor. even if you run all this thread they wouldn't work at same time, they just will work in async way.

And also i recommend you don not image bicycle and use jmeter for testing.

Grigoriev Nick
  • 1,099
  • 8
  • 24
  • Thank you , But Jmeter scripts can't be reuseable and good in my opion . – Jerry Cai Oct 14 '13 at 08:36
0

As pointed out elsewhere, using a blocking client is not a good idea for stress testing as it stresses the client more than the server. A better choice would be to write your code using the AsyncHttpClient dependency. If you are on Eclipse, you could also try the RequestAge plugin, wherein you write your test scripts in Javascript.

Disclosure: RequestAge was written by the author of this answer.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436