Code Monkey home page Code Monkey logo

Comments (8)

BrianNichols avatar BrianNichols commented on August 23, 2024

There are performance implications for allowing event loops to be closed separately. Gaps in the array of event loops would be created which needs to be accounted for when assigning async commands to event loops. This implies at least one extra volatile reference.

Most applications initialize all event loops at startup and close all event loops at shutdown. What is
your use-case for closing an event loop at any time?

from aerospike-client-c.

XeCycle avatar XeCycle commented on August 23, 2024

OK I see your point in implicitly used event loops, so it may involve significant changes.

My use case is like, our app is in two parts, which originally runs as separate processes. And now we want to merge them in a same process, but running on different threads, so that we have lighter message passing between them. What's different is that, one part of it runs as several instances, starting and stopping on demand, and of course we want a graceful shutdown. Well, mostly an all-isolated environment, except for address space.

So, given that all attached loops are managed as a whole, maybe I am looking for an "aerospike_context" or the like, instead of the static variables now in use.

from aerospike-client-c.

BrianNichols avatar BrianNichols commented on August 23, 2024

We will research dynamic event loop sizing as a possible future enhancement. No concrete decision has been made.

from aerospike-client-c.

BrianNichols avatar BrianNichols commented on August 23, 2024

We have decided not to implement dynamic event loop closing for a number of reasons.

  1. as_event_loop_get() round-robin event loop assignment would require a lock. This would incur a performance penalty for all async users.

  2. Handling simultaneous event loop open/close/assignment is a complex process, especially when the close operation lock must transcend multiple iterations (lock, queue event loop close, process event loop close, unlock).

  3. Each as_node instance maintains a pool of sockets for each event loop. If an event loop is closed, the sockets associated with the event loop would need to be assigned to other event loops or just closed. The problem is event loops have no current knowledge of clusters or nodes. This would require the client to maintain a thread-safe list of all opened clusters. The client could then iterate on all nodes in all clusters and close or reassign the associated sockets. This extra overhead is not currently necessary because all clusters/nodes must be closed before closing event loops.

Note that external event loops can be opened (but not closed) dynamically with the current client. First, define a fixed capacity limit with as_event_set_external_loop_capacity(). Then, add external event loops with as_event_set_external_loop() at any time until the capacity is reached.

from aerospike-client-c.

XeCycle avatar XeCycle commented on August 23, 2024

What about creating random event loops on the heap without adding to the global as_event_loops? So that external loops are not considered in the round-robin choosing, and is completely external.

from aerospike-client-c.

BrianNichols avatar BrianNichols commented on August 23, 2024

The main obstacle is that there is a socket pool for every node/event loop combination. It was done that way so each socket get/put does not have to be thread-safe. #3 is still a problem in your scenario.

It may be possible to add a configuration variable that instructs nodes to provide a connection pool per node only and then use thread-safe (slower) socket get/put. This would mean #3 is not a problem, because event loops could be disassociated from socket pools. We will do some more research to see if that is feasible.

from aerospike-client-c.

BrianNichols avatar BrianNichols commented on August 23, 2024

Supporting two fundamentally different types of async socket pools complicates the code too much. I'm afraid our original decision stands.

from aerospike-client-c.

XeCycle avatar XeCycle commented on August 23, 2024

Okay I give up, close at your will. Maybe we resort to a single thread for AS access.

from aerospike-client-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.