简体   繁体   中英

Is this long running request a valid use case for java asynchronous servlets?

I've been reading about asynchronous servlets in an attempt to see if it fits my use case.

The server will receive long-running requests that take time to read from the db, and process each message.

Here is the basic flow:

  1. Client makes a request to validate some data.
  2. Server receives a request for the long-running process (~1-2 minutes)
    1. Request needs to talk to a db (redis, in my case) to grab 100,000 docs in batches.
    2. Processing occurs for each doc, and if it is valid, it is written to the client. Similarly, upto 25 sample docs are written to the client.
    3. When the full data set is processed (but no more than 25 docs are written), a result is calculated and sent.
    4. Connection is successfully closed.

So there is a db wait, which all similar requests will have, and then the processing for each doc, which happens in the same thread.

Is there any benefit to switching to async servlets versus a regular synchronous servlet in this case?

Additionally, if I do use an async servlet, would there be any benefit in also trying to parallelize the processing of the docs with thread pools? It seems like I won't be getting any additional benefit, but want to clarify this as well.

Thanks for your help!

Is there any benefit to switching to async servlets versus a regular synchronous servlet in this case?

Yes. In fact it is the use case that all manuals tells you "async servlets are useful for this"

Additionally, if I do use an async servlet, would there be any benefit in also trying to parallelize the processing of the docs with thread pools? It seems like I won't be getting any additional benefit, but want to clarify this as well.

Unrelated. Async servlets just releases resources so your server keeps answering petitions even if lots of servlets are waiting for results. It is not related to the speed of answering the asynchronized request.

Any benefit that you get from optimizing your logic will be good for the server and the user, but it would be good either if you are using async servlets or sync servlets.

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