Arun Arun - 1 month ago 10
MySQL Question

Better scaling Spring application using @Async for large number of database insert or update queries

I have a spring REST controller whose sole purpose is to create or update a record every time when mobile client launches or boot app. This URL will be fired only when user launches app or if it comes to foreground after resume ( ie, when user press device home button to something else and after a while, user press the app icon to bring it to the foreground from memory ).

The expected number of requests for this URL is around 600 requests per minute.

To scale this application, is it better to put the database (MySql) create / update logic of spring controller in a separate thread or using @Async feature of Spring ?
So that it won't hold the system port for a very long time and one machine can handle large number of requests before my web server ( glassfish ) pushes requests to the waiting queue.

Also,
The expected table size or the number of records in this table is around 10M - 30M.

Answer

I personally wouldn't bother with an async call at least to start with. Create a jmeter script and fire some load at it and see how it performs.

If you start to get slow down using Async with a threadPoolExecutor behind it (that you can easily configure) is certainly a valid option. With these type of things configuring the queue size and number of threads (both for your thread pool executor and your web container) is a bit of a black art which is where something like jmeter and a good profiling tool such as Yourkit come into their own.