Skip to content
Permalink
Browse files
[JENKINS-36871] Blocking I/O is faster when you have very few connect…
…ions, so allow preference declaration
  • Loading branch information
stephenc committed Aug 5, 2016
1 parent b5656c0 commit 1edda2be2a24732a2ff184207d859468d69b4877
Showing 9 changed files with 422 additions and 59 deletions.
@@ -66,10 +66,11 @@ public class JnlpProtocol1Handler extends LegacyJnlpProtocolHandler<LegacyJnlpCo
* @param clientDatabase the client database to use or {@code null} if client connections will not be required.
* @param threadPool the {@link ExecutorService} to run tasks on.
* @param hub the {@link NioChannelHub} to use or {@code null} to use blocking I/O.
* @param preferNio {@code true} means that the protocol should attempt to use NIO if possible
*/
public JnlpProtocol1Handler(@Nullable JnlpClientDatabase clientDatabase, @Nonnull ExecutorService threadPool,
@Nullable NioChannelHub hub) {
super(clientDatabase, threadPool, hub);
@Nullable NioChannelHub hub, boolean preferNio) {
super(clientDatabase, threadPool, hub, preferNio);
}

/**
@@ -69,10 +69,11 @@ public class JnlpProtocol2Handler extends LegacyJnlpProtocolHandler<LegacyJnlpCo
* @param clientDatabase the client database to use or {@code null} if client connections will not be required.
* @param threadPool the {@link ExecutorService} to run tasks on.
* @param hub the {@link NioChannelHub} to use or {@code null} to use blocking I/O.
* @param preferNio {@code true} means that the protocol should attempt to use NIO if possible.
*/
public JnlpProtocol2Handler(@Nullable JnlpClientDatabase clientDatabase, @Nonnull ExecutorService threadPool,
@Nullable NioChannelHub hub) {
super(clientDatabase, threadPool, hub);
@Nullable NioChannelHub hub, boolean preferNio) {
super(clientDatabase, threadPool, hub, preferNio);
}

/**
@@ -25,19 +25,16 @@

import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;
import hudson.remoting.SocketChannelStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -144,8 +141,8 @@ public class JnlpProtocol3Handler extends LegacyJnlpProtocolHandler<Jnlp3Connect


public JnlpProtocol3Handler(@Nullable JnlpClientDatabase clientDatabase, @Nonnull ExecutorService threadPool,
@Nullable NioChannelHub hub) {
super(clientDatabase, threadPool, hub);
@Nullable NioChannelHub hub, boolean preferNio) {
super(clientDatabase, threadPool, hub, preferNio);
}

/**
@@ -26,6 +26,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;
import hudson.remoting.SocketChannelStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -100,10 +101,12 @@ public class JnlpProtocol4Handler extends JnlpProtocolHandler<Jnlp4ConnectionSta
* @param ioHub the {@link IOHub}.
* @param context the {@link SSLContext}.
* @param needClientAuth {@code} to force all clients to have a client certificate in order to connect.
* @param preferNio {@code true} means that the protocol should attempt to use NIO if possible.
*/
public JnlpProtocol4Handler(@Nullable JnlpClientDatabase clientDatabase, @Nonnull ExecutorService threadPool,
@Nonnull IOHub ioHub, @Nonnull SSLContext context, boolean needClientAuth) {
super(clientDatabase);
@Nonnull IOHub ioHub, @Nonnull SSLContext context, boolean needClientAuth,
boolean preferNio) {
super(clientDatabase, preferNio);
this.threadPool = threadPool;
this.ioHub = ioHub;
this.context = context;
@@ -188,10 +191,10 @@ public Future<Channel> connect(@Nonnull Socket socket, @Nonnull Map<String, Stri
*/
private NetworkLayer createNetworkLayer(Socket socket) throws IOException {
NetworkLayer networkLayer;
SocketChannel socketChannel = socket.getChannel();
SocketChannel socketChannel = isPreferNio() ? socket.getChannel() : null;
if (socketChannel == null) {
networkLayer = new BIONetworkLayer(ioHub, Channels.newChannel(socket.getInputStream()),
Channels.newChannel(socket.getOutputStream()));
networkLayer = new BIONetworkLayer(ioHub, Channels.newChannel(SocketChannelStream.in(socket)),
Channels.newChannel(SocketChannelStream.out(socket)));
} else {
networkLayer = new NIONetworkLayer(ioHub, socketChannel, socketChannel);
}
@@ -353,6 +356,9 @@ public void run() {
@NonNull
public ChannelBuilder decorate(@NonNull ChannelBuilder builder) {
assert remoteHeaders != null;
if (!client) {
builder.withMode(Channel.Mode.NEGOTIATE);
}
event.fireBeforeChannel(builder);
return event.getChannelBuilder();
}

0 comments on commit 1edda2b

Please sign in to comment.