Java server event loop

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Event loop for processing your Java based application events

alexpractice/eventloop

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Simple event loop for processing custom application events

#####1. Configure Event Publisher and Event Loop.

EventBus eventBus = new EventBusImpl(); EventLoop eventLoop = new EventLoopImpl(eventBus); EventPublisher eventPublisher = new EventPublisherImpl(eventBus); eventLoop.addEventHandler(simpleEventHandler); eventLoop.addEventHandler(urlCheckingEventHandler); eventLoop.addEventHandler(isOddNumberResultEventHandler); eventLoop.addEventHandler(isOddNumberCheckingEventHandler);

#####2. Start Event Loop after configuring

#####3. Publish events through the Event Publisher

SimpleEvent simpleEvent = new SimpleEvent("hello world!"); eventPublisher.publish(simpleEvent);

You may see the working example into Test.java

I’ll publish thats event-loop library in maven central repository later

About

Event loop for processing your Java based application events

Источник

Create Event Loops

Create event loops that will process async commands. Each EventLoops instance can be shared among multiple AerospikeClient instances. The number of event loops for an EventLoops instance should approximate the number of cpu cores on your machine that are reserved for AerospikeClient processing. Both Netty and direct NIO event loops are supported.

Event Policy​

Each event loop is configured with an EventPolicy instance.

EventPolicy eventPolicy = new EventPolicy(); 

Event Loop Throttle​

Async commands are immediately executed on an event loop by default. The event loop can be overloaded if the rate of commands executed on the event loop consistently exceeds the rate the event loop can process those commands. This can cause the client to consume too many sockets which negatively affects performance. In extreme cases, the application can run out of sockets.

These EventPolicy defaults assume the user will apply an external throttle to mitigate event loop overload. The example AsyncTest performs this throttle by seeding the event loop with N commands and running exactly one more command when a command completes.

If the user does not apply an external throttle, it’s important to set EventPolicy.maxCommandsInProcess to limit the number of concurrent commands allowed on the event loop. Excess commands are placed on a delay queue without an assigned socket connection until a command slot becomes available. When a slot becomes available, the command will be assigned a socket connection and executed on the event loop.

Create Netty Event Loops​

Netty allows users to share their existing event loops with AerospikeClient which can improve performance. Netty event loops are also required when using TLS connections. Netty is an optional external library dependency.

Netty NIO​

import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;  import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy;  EventPolicy eventPolicy = new EventPolicy();  // Create 4 Netty event loops using the Netty API. EventLoopGroup group = new NioEventLoopGroup(4);  // Create Aerospike compatibile wrapper of Netty event loops. EventLoops eventLoops = new NettyEventLoops(eventPolicy, group); 

Netty EPOLL​

import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.EpollEventLoopGroup;  import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy;  EventPolicy eventPolicy = new EventPolicy();  // Create 4 Netty event loops using the Netty API. EventLoopGroup group = new EpollEventLoopGroup(4);  // Create Aerospike compatibile wrapper of Netty event loops. EventLoops eventLoops = new NettyEventLoops(eventPolicy, group); 

Create Direct NIO Event Loops​

Direct NIO event loops are an alternative implementation that is lighter weight and slightly faster than Netty defaults when not sharing event loops. Direct NIO does not have an external library dependency.

import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NioEventLoops;  EventPolicy eventPolicy = new EventPolicy();  // Create 4 Aerospike NIO event loops directly. EventLoops eventLoops = new NioEventLoops(eventPolicy, 4); 

Источник

Читайте также:  Converting list to tuple in python
Оцените статью