-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best Practices for Using Aerospike C Client with a Separate UV Loop #155
Comments
That api doc quote assumed that async applications always benefit from sharing event loops and suggested that creating dedicated aerospike event loops should only be necessary when the application is not async. In your case, creating dedicated aerospike event loops using as_event_create_loops() does seem to make sense. I will change the documentation to be more clear. We use as_event_create_loops() in our benchmarks, examples and test applications and have not observed that busy with no workload scenario. My suggestions are:
|
@BrianNichols Thank you for your response! Just to clarify, our goal is to call Would this approach be available and if there is some potential issues? And if so is there an example for doing that? We greatly appreciate your insights! Versions:
|
Yes, this approach can work. as_event_create_loops() will spawn a new thread for each new event loop. Each thread will be assigned to a cpu by the operating system (usually by round-robin) and some threads might run on the same cpu as your application's uv_loop. Running multiple threads on the same cpu can cause performance issues if one of the threads has heavy cpu usage. Another potential issue is running Aerospike commands from your application's uv_loop. Since the threads are now separate, the client must queue the command to the Aerospike event loop thread via a mutex lock. The Aerospike event loop thread also retrieves the command from the queue via the same lock. Conversely, your application might have to queue Aerospike command results back to your application's uv_loop thread if it needs to process it there. Passing commands and/or data between threads must be done atomically and does incur an added cost. |
Thanks again, Brian.
|
|
Hello Aerospike community,
We have been using Aerospike in conjunction with our server's main uv_loop for several years without issues. However, we are now exploring the option of assigning Aerospike its own thread and loop to reduce the load on our main loop. While attempting this, we encountered several challenges.
Initially, we tried using
as_event_create_loops
, and it seemed to work fine locally. However, when we deployed it to our development environment, we experienced significant issues. The loop appeared to become busy, consuming an entire CPU core, which effectively busted our online environment.The documentation for as_event_create_loops mentions:
We are trying to understand if this implies that our server, which is based on uv_loop, cannot use this method to create a separate loop for Aerospike. We also tried managing a separate thread and running a uv_loop ourselves with as_event_set_external_loop, but this led to issues with dangling objects and other hard-to-resolve problems.
Could anyone advise on the best practices for assigning Aerospike its own event loop, while allowing our main loop to focus on other tasks without overwhelming the CPU? We would greatly appreciate any guidance.
Thanks
The text was updated successfully, but these errors were encountered: