io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscAtomicArrayQueue Java Examples
The following examples show how to use
io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscAtomicArrayQueue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyClientConnector.java From rpc-benchmark with Apache License 2.0 | 6 votes |
public Response execute(Request request, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { final long requestId = request.getRequestId(); final CompletableFuture<Response> future = new CompletableFuture<>(); try { futureContainer.addFuture(requestId, future); int index = ThreadLocalRandom.current().nextInt(CONNECT_COUNT); Channel channel = channels[index]; MpscAtomicArrayQueue<Request> queue = queues[index]; while (!queue.offer(request)) { batchSend(channel, queue); } batchSend(channel, queue); return future.get(); } finally { futureContainer.remove(requestId); } }
Example #2
Source File: NettyClientConnector.java From rpc-benchmark with Apache License 2.0 | 6 votes |
private void doConnect(EventLoopGroup loupGroup, Class<? extends SocketChannel> serverChannelClass, boolean isEpoll) throws InterruptedException { final Bootstrap bootstrap = new Bootstrap(); if (isEpoll) { bootstrap.option(EpollChannelOption.SO_REUSEPORT, true); } bootstrap.option(ChannelOption.SO_REUSEADDR, true); bootstrap.option(ChannelOption.SO_RCVBUF, 256 * 1024); bootstrap.option(ChannelOption.SO_SNDBUF, 256 * 1024); bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, // new WriteBufferWaterMark(1024 * 1024, 2048 * 1024)); bootstrap.group(loupGroup); bootstrap.channel(serverChannelClass); bootstrap.handler(new BenchmarkChannelInitializer(futureContainer)); for (int i = 0; i < CONNECT_COUNT; i++) { channels[i] = bootstrap.connect(host, port).sync().channel(); queues[i] = new MpscAtomicArrayQueue<>(4 * 1024); } }
Example #3
Source File: MpscBenchmark.java From java-Kcp with Apache License 2.0 | 5 votes |
@Setup(Level.Trial) public void setUp() { switch (implementation) { case PARAM_UNSAFE: queue = new MpscArrayQueue<>(CAPACITY); break; case PARAM_AFU: queue = new MpscAtomicArrayQueue<>(CAPACITY); break; case PARAM_JDK: queue = new ArrayBlockingQueue<>(CAPACITY); break; case PARAM_LINKED: queue = new MpscChunkedArrayQueue<>(CAPACITY); break; case PARAM_JDK_LINK: queue = new LinkedBlockingQueue<>(CAPACITY); break; case PARAM_LINKED_GROUP: queue = new MpscGrowableAtomicArrayQueue<>(CAPACITY); break; case PARAM_MPSC_LINKED: queue = new MpscLinkedQueue<>(); break; case PARAM_MPMC_LINKED_ATOMICQUEUE: queue = new MpscLinkedAtomicQueue<>(); break; default: throw new UnsupportedOperationException("Unsupported implementation " + implementation); } }
Example #4
Source File: NettyClientConnector.java From rpc-benchmark with Apache License 2.0 | 5 votes |
private void batchSend(Channel channel, MpscAtomicArrayQueue<Request> queue) { if (queue.isEmpty()) { return; } channel.eventLoop().execute(() -> { if (queue.isEmpty()) { return; } ByteBuf byteBuf = channel.alloc().ioBuffer(1024 * 4); for (int i = 0; i < 64; i++) { Request request = queue.poll(); if (request == null) { break; } try { FastestSerializer.writeRequest(byteBuf, request); } catch (Throwable t) { t.printStackTrace(); channel.close(); } } if (byteBuf.isReadable()) { channel.writeAndFlush(byteBuf, channel.voidPromise()); } else { byteBuf.release(); } }); }