FAQ - What are Best Practices for Shutting Down Async Eventloops

The Aerospike Knowledge Base has moved to https://support.aerospike.com. Content on https://discuss.aerospike.com is being migrated to either https://support.aerospike.com or https://docs.aerospike.com. Maintenance on articles stored in this repository ceased on December 31st 2022 and this article may be stale. If you have any questions, please do not hesitate to raise a case via https://support.aerospike.com.

FAQ - What are Best Practices for Shutting Down Async Eventloops

Detail

When using Aerospike clients in asynchrous mode it may be advantageous to clean up all outstanding calls during shutdown. What is the proper way to do this?

Answer

How you clean up outstanding calls depends upon whether the eventloop concerned is internal or external.

Internal Eventloops

Internal eventloops are created by either as_event_create_loops() or as_create_event_loops().

  • Call aerospike_close() on all active Aerospike instances from a non-eventloop thread. This means that the client blocks the current thread until active commands are complete on that Aerospike instance. If this is called from an eventloop thread, the client cannot block as it would deadlock the eventloop thread.
  • Call aerospike_destroy() on closed Aerospike instances.
  • Call as_event_close_loops() to send a close command signal to all event loops. The current thread will be blocked until all eventloops shut down. There is no need to call as_event_destroy_loops() as it is called implicitly by as_event_close_loops().
  • There is no timeout on this and so the thread blocks until all internal eventloops complete.

External Eventloops

External eventloops are created using as_event_Set_external_loop_capacity() and as_event_set_external_loop(). Use the following steps to shut them down.

  • Call aerospike_close() on all active Aerospike instances from a non-eventloop thread. This ensures that the client blocks the current thread until active commands are completed on the Aerospike instance concerned. As with internal eventloops, if an eventloop thread is used to do the close call, it deadlocks the eventloop.
  • Call aerospike_destroy() on the now-closed instances.
  • Call aas_event_close_loop() on each eventloop thread.
  • Join on all external eventloop threads.
  • Call as_event_destroy_loops().

Notes

  • as_event_close_loops() and as_event_close_loop() fail if the close command can’t be sent to any event loop. If the close command can’t be pushed onto the event loop queue, the queue may be out of memory as it resizes after it reaches current capacity. This is considered unlikely, though it is possible.
  • It is not recommended to retry as_event_close_loops(). If the application runs out of memory resizing the queue, it is likely that this will cause an application crash.
  • If there is a memory leak, as_event_close_loops() will show up in any memory leak analysis.

Keywords

EVENTLOOP CLOSE SHUTDOWN ASYNCHRONOUS

Timestamp

October 2021