-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: Netty recently added support for [TCP fast open](https://tools.ietf.org/html/rfc7413) on the client, and has had server support for a while. We currently don't expose the necessary configuration knobs to enable this feature, but it may be able to reduce round trips and reduce connection setup latency. Modifications: - Add socket options to configure client and server TCP fast open. - Add mechanism to configure the listen/acceptor socket options, and use this for the backlog option which was an outlier. Result: TCP Fast Open can be enabled for client and server. Note that it is only supported by Netty's native EPOLL transport on linux, and only initiated on the client when TLS is enabled.
- Loading branch information
1 parent
d4037d3
commit 808b31c
Showing
12 changed files
with
407 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/TcpFastOpenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright © 2020 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.http.netty; | ||
|
||
import io.servicetalk.concurrent.internal.ServiceTalkTestTimeout; | ||
import io.servicetalk.http.api.BlockingHttpClient; | ||
import io.servicetalk.http.api.HttpResponseStatus; | ||
import io.servicetalk.http.api.HttpServerBuilder; | ||
import io.servicetalk.http.api.SingleAddressHttpClientBuilder; | ||
import io.servicetalk.transport.api.HostAndPort; | ||
import io.servicetalk.transport.api.ServerContext; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.Timeout; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.net.SocketOption; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import static io.servicetalk.transport.api.ServiceTalkSocketOptions.TCP_FASTOPEN_BACKLOG; | ||
import static io.servicetalk.transport.api.ServiceTalkSocketOptions.TCP_FASTOPEN_CONNECT; | ||
import static io.servicetalk.transport.netty.internal.AddressUtils.localAddress; | ||
import static io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.singletonMap; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public class TcpFastOpenTest { | ||
@Rule | ||
public final Timeout timeout = new ServiceTalkTestTimeout(); | ||
@SuppressWarnings("rawtypes") | ||
private final Map<SocketOption, Object> serverListenOptions; | ||
@SuppressWarnings("rawtypes") | ||
private final Map<SocketOption, Object> clientOptions; | ||
|
||
public TcpFastOpenTest( | ||
@SuppressWarnings("rawtypes") final Map<SocketOption, Object> serverListenOptions, | ||
@SuppressWarnings("rawtypes") final Map<SocketOption, Object> clientOptions) { | ||
this.serverListenOptions = serverListenOptions; | ||
this.clientOptions = clientOptions; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: server opts={0} client opts={1}") | ||
public static Collection<Object[]> sslProviders() { | ||
return asList( | ||
new Object[]{emptyMap(), emptyMap()}, | ||
new Object[]{emptyMap(), clientTcpFastOpenOptions()}, | ||
new Object[]{serverTcpFastOpenOptions(), emptyMap()}, | ||
new Object[]{serverTcpFastOpenOptions(), clientTcpFastOpenOptions()} | ||
); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static Map<SocketOption, Object> clientTcpFastOpenOptions() { | ||
return singletonMap(TCP_FASTOPEN_CONNECT, true); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static Map<SocketOption, Object> serverTcpFastOpenOptions() { | ||
return singletonMap(TCP_FASTOPEN_BACKLOG, 1); | ||
} | ||
|
||
@Test | ||
public void requestSucceedsEvenIfTcpFastOpenNotEnabledOrSupported() throws Exception { | ||
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)); | ||
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : serverListenOptions.entrySet()) { | ||
@SuppressWarnings("unchecked") | ||
SocketOption<Object> option = entry.getKey(); | ||
serverBuilder.listenSocketOption(option, entry.getValue()); | ||
} | ||
try (ServerContext serverContext = serverBuilder.listenBlockingAndAwait( | ||
(ctx, request, responseFactory) -> responseFactory.ok()); | ||
BlockingHttpClient client = newClientBuilder(serverContext).buildBlocking()) { | ||
assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status()); | ||
} | ||
} | ||
|
||
private SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> newClientBuilder( | ||
ServerContext serverContext) { | ||
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = | ||
HttpClients.forSingleAddress(serverHostAndPort(serverContext)); | ||
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : clientOptions.entrySet()) { | ||
@SuppressWarnings("unchecked") | ||
SocketOption<Object> option = entry.getKey(); | ||
builder.socketOption(option, entry.getValue()); | ||
} | ||
return builder; | ||
} | ||
} |
Oops, something went wrong.