FAQ - What are Best Practices for Shutting Down Async Eventloops

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

© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.