# Vert.x aerospike client to use context-bound event loop

**URL:** <https://discuss.aerospike.com/t/vert-x-aerospike-client-to-use-context-bound-event-loop/9704>\
**Category:** Java Client\
**Tags:** java\
**Created:** [August 29, 2022, 10:23am UTC](https://discuss.aerospike.com/t/vert-x-aerospike-client-to-use-context-bound-event-loop/9704 "2022-08-29T10:23:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sleshJdev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sleshjdev/32/1783_2.png) [@sleshJdev](https://discuss.aerospike.com/u/sleshJdev)\
**Post date:** [August 29, 2022, 10:23am UTC](https://discuss.aerospike.com/t/vert-x-aerospike-client-to-use-context-bound-event-loop/9704/1 "2022-08-29T10:23:20Z")

</div>

Standard [java aerospike client](https://developer.aerospike.com/client/java)’s methods have overloads allowing to provide [EventLoop](https://github.com/aerospike/aerospike-client-java/blob/master/client/src/com/aerospike/client/async/EventLoop.java) as an argument. When running in vert.x that client is not aware of context-bounded event loop and just fallbacks to `if (eventLoop == null) { eventLoop = cluster.eventLoops.next(); }` which could(and likely does) causes context switching/level of concurrency which in turn affects performance (it’s still in theory, but I want to prove it), because there is no guarantee that aerospike requests will run on the same event loop as coming http request according to [Vert.x Multi Reactor](https://vertx.io/docs/vertx-core/java/#_reactor_and_multi_reactor) pattern. Open source aerospike clients like [vertx-aerospike-client](https://github.com/dream11/vertx-aerospike-client) also have such a disadvantage. Using vert.x there is no way(at least I’m not aware of) to retrieve context-bounded event loop and pass it to aerospike client.

Vert.x has method to retrieve Context [Vertx.currentContext()](https://github.com/eclipse-vertx/vert.x/blob/2439c849549b08a1e7ffee8f09eae886c9fe88f6/src/main/java/io/vertx/core/Vertx.java#L116) but retrieving EventLoop is not available.

Any ideas?

> <https://stackoverflow.com/questions/73527320/vert-x-aerospike-client-to-use-context-bound-event-loop>

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [August 29, 2022, 5:57pm UTC](https://discuss.aerospike.com/t/vert-x-aerospike-client-to-use-context-bound-event-loop/9704/2 "2022-08-29T17:57:26Z")

</div>

One possible solution is to create a map (usually IdentityHashMap) of all Vertx context(s) to Aerospike EventLoop(s). Then, EventLoop can be looked up by the current context.

If Vertx supports user-defined tags on the context, then setting this tag to EventLoop would be another alternative.

---

<div class="post-metadata">

**Author:** ![sleshJdev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sleshjdev/32/1783_2.png) [@sleshJdev](https://discuss.aerospike.com/u/sleshJdev)\
**Post date:** [August 30, 2022, 10:03am UTC](https://discuss.aerospike.com/t/vert-x-aerospike-client-to-use-context-bound-event-loop/9704/3 "2022-08-30T10:03:41Z")

</div>

Sounds like a working solution, thanks. I’ll try it out.
