简体   繁体   中英

Should I send synchronous or asynchronous requests when load testing a web app?

When load testing a web app, I can either

  1. send synchronous requests in multiple threads, or
  2. use an asynchronous client and handle response in callbacks.

With the multi-thread approach, requests within the same thread are only sent after the last response is received. Concurrency is achieved through threads.

With the asynchronous approach, concurrent requests are sent in quick succession. However, requests has to be sent periodically, giving the event loop enough time to handle the responses.

For example, using python, I can either use requests to send requests (synchronous), or I can use twisted or tornado 's asynchronous HTTP client.

Which is the way to go with load testing?

Because load testing is often IO bound operation (disclaimer: this varies by the nature of your system which you did not describe in your question) the asynchronous approach is better. Asynchronous approach does less thread context switching which would unnecessarily tax CPU even there is little for CPU to do.

However I suggest do not try to invent your own load testing tool especially if you have no experience of this. Instead, use stock software like JMeter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM