3scale / apisonator

Red Hat 3scale API Management Apisonator backend
https://3scale.net
Apache License 2.0
36 stars 27 forks source link

Async worker: Use Async tools to limit concurrency #361

Closed jlledom closed 4 months ago

jlledom commented 5 months ago

The asynchronous worker was using a custom method to control the amount of concurrent tasks in the reactor. However, Async provides some tools for this. Better use them rather than inventing the wheel.

Check: https://socketry.github.io/async/guides/best-practices/index

This also includes some minor changes to:

How to verify:

  1. Set CONFIG_ASYNC_WORKER_MAX_CONCURRENT_JOBS to the desired number.
  2. Use hey to generate fake load
    ./hey_linux_amd64 -z 60s -c 60 -q 20 "http://localhost:3001/transactions/authrep.xml?service_token=TOKEN&service_id=2&usage%5Bhits%5D=1&user_key=APP_USER_KEY"
  3. Check with puts semaphore.count that CONFIG_ASYNC_WORKER_MAX_CONCURRENT_JOBS is never exceeded
jlledom commented 5 months ago

@akostadinov @mayorova I made some changes from your comments in the call:

jlledom commented 4 months ago

@akostadinov I implemented your suggestions