[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..d8d5286b1 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -34,6 +34,7 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +78,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +135,22 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +// when host of createEndpoint is not ip but a hostName +// get from remoteAddress will return null +// in this time need to try again with remoteName +// connected is a low frequency method, this try logic will not cause performance problem + +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +if (clientEndpointMetric == null) { + SocketAddressImpl address = new SocketAddressImpl(remoteAddress.port(), remoteName); + clientEndpointMetric = this.clientEndpointMetricManager.getClientEndpointMetric(address); +} +// it's better to be done in endpointConnected +// but there is bug before vertx 3.6.0 vertx not invoke endpointConnected for http2 +// to avoid this bug, we move the logic here +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java index e7455da26..ced194cd7 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java @@ -104,7 +104,12 @@ protected static void run() throws Throwable { // .. testSpringBoot2Standalone(); + +testHttp2CStandalone(); + testSpringBoot2Servlet(); +//http2 +testHttp2Standalone(); deploys.getEdge().stop(); } @@ -145,6 +150,42 @@ private static void testStandalone() throws Throwable { deploys.getBaseProducer().stop(); } + private static void testHttp2CStandalone() throws Throwable { +deploys.getBaseHttp2CProducer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2CProducer().stop(); + } + + private static void testHttp2Standalone() throws Throwable { +deploys.getBaseHttp2Producer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2Producer().stop(); + } +
[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..d8d5286b1 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -34,6 +34,7 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +78,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +135,22 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +// when host of createEndpoint is not ip but a hostName +// get from remoteAddress will return null +// in this time need to try again with remoteName +// connected is a low frequency method, this try logic will not cause performance problem + +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +if (clientEndpointMetric == null) { + SocketAddressImpl address = new SocketAddressImpl(remoteAddress.port(), remoteName); + clientEndpointMetric = this.clientEndpointMetricManager.getClientEndpointMetric(address); +} +// it's better to be done in endpointConnected +// but there is bug before vertx 3.6.0 vertx not invoke endpointConnected for http2 +// to avoid this bug, we move the logic here +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java index e7455da26..ced194cd7 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java @@ -104,7 +104,12 @@ protected static void run() throws Throwable { // .. testSpringBoot2Standalone(); + +testHttp2CStandalone(); + testSpringBoot2Servlet(); +//http2 +testHttp2Standalone(); deploys.getEdge().stop(); } @@ -145,6 +150,42 @@ private static void testStandalone() throws Throwable { deploys.getBaseProducer().stop(); } + private static void testHttp2CStandalone() throws Throwable { +deploys.getBaseHttp2CProducer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2CProducer().stop(); + } + + private static void testHttp2Standalone() throws Throwable { +deploys.getBaseHttp2Producer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2Producer().stop(); + } +
[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..d8d5286b1 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -34,6 +34,7 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +78,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +135,22 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +// when host of createEndpoint is not ip but a hostName +// get from remoteAddress will return null +// in this time need to try again with remoteName +// connected is a low frequency method, this try logic will not cause performance problem + +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +if (clientEndpointMetric == null) { + SocketAddressImpl address = new SocketAddressImpl(remoteAddress.port(), remoteName); + clientEndpointMetric = this.clientEndpointMetricManager.getClientEndpointMetric(address); +} +// it's better to be done in endpointConnected +// but there is bug before vertx 3.6.0 vertx not invoke endpointConnected for http2 +// to avoid this bug, we move the logic here +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java index e7455da26..ced194cd7 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java @@ -104,7 +104,12 @@ protected static void run() throws Throwable { // .. testSpringBoot2Standalone(); + +testHttp2CStandalone(); + testSpringBoot2Servlet(); +//http2 +testHttp2Standalone(); deploys.getEdge().stop(); } @@ -145,6 +150,42 @@ private static void testStandalone() throws Throwable { deploys.getBaseProducer().stop(); } + private static void testHttp2CStandalone() throws Throwable { +deploys.getBaseHttp2CProducer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2CProducer().stop(); + } + + private static void testHttp2Standalone() throws Throwable { +deploys.getBaseHttp2Producer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2Producer().stop(); + } +
[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..d8d5286b1 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -34,6 +34,7 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +78,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +135,22 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +// when host of createEndpoint is not ip but a hostName +// get from remoteAddress will return null +// in this time need to try again with remoteName +// connected is a low frequency method, this try logic will not cause performance problem + +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +if (clientEndpointMetric == null) { + SocketAddressImpl address = new SocketAddressImpl(remoteAddress.port(), remoteName); + clientEndpointMetric = this.clientEndpointMetricManager.getClientEndpointMetric(address); +} +// it's better to be done in endpointConnected +// but there is bug before vertx 3.6.0 vertx not invoke endpointConnected for http2 +// to avoid this bug, we move the logic here +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java index e7455da26..ced194cd7 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java @@ -104,7 +104,12 @@ protected static void run() throws Throwable { // .. testSpringBoot2Standalone(); + +testHttp2CStandalone(); + testSpringBoot2Servlet(); +//http2 +testHttp2Standalone(); deploys.getEdge().stop(); } @@ -145,6 +150,42 @@ private static void testStandalone() throws Throwable { deploys.getBaseProducer().stop(); } + private static void testHttp2CStandalone() throws Throwable { +deploys.getBaseHttp2CProducer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2CProducer().stop(); + } + + private static void testHttp2Standalone() throws Throwable { +deploys.getBaseHttp2Producer().ensureReady(); + +ITJUnitUtils.addProducer("it-producer"); + +runShareTestCases(); + +// currently not support update 3rd url, so only test once +ITJUnitUtils.run(Test3rdPartyInvocation.class); + +//as setMaxInitialLineLength() is not work for http2, do not need +// ITJUnitUtils.runWithRest(TestRestServerConfig.class) +ITJUnitUtils.run(TestRestServerConfigEdge.class); + +ITJUnitUtils.popProducer(); +deploys.getBaseHttp2Producer().stop(); + } +
[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..3fb9af337 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -19,6 +19,8 @@ import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultClientEndpointMetric; import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultClientEndpointMetricManager; import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultHttpSocketMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; @@ -34,6 +36,9 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHttpClientMetrics.class); + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +82,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +139,11 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +//we can get endpointMetric info here, so set the endpointMetric info directly +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java index 05f73a7f8..2ce5620fa 100644 --- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java +++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java @@ -61,9 +61,7 @@ public void init(Vertx vertx) throws Exception { HttpClientOptions httpClientOptions = createHttpClientOptions(); clientMgr = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptions)); -HttpClientOptions httpClientOptionshttp2 = createHttpClientOptions(); - httpClientOptionshttp2.setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2); -httpClientOptionshttp2.setHttp2ClearTextUpgrade(false); +HttpClientOptions httpClientOptionshttp2 = createHttp2ClientOptions(); clientMgrHttp2 = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptionshttp2)); @@ -87,6 +85,21 @@ private static HttpClientOptions createHttpClientOptions() { return httpClientOptions; } + private static HttpClientOptions createHttp2ClientOptions() { +HttpClientOptions httpClientOptions = new HttpClientOptions(); + httpClientOptions.setMaxPoolSize(TransportClientConfig.getConnectionMaxPoolSize()) +.setUseAlpn(true) + .setIdleTimeout(TransportClientConfig.getConnectionIdleTimeoutInSeconds()) + .setHttp2MultiplexingLimit(TransportClientConfig.getHttp2MultiplexingLimit()) + .setHttp2MaxPoolSize(TransportClientConfig.getHttp2ConnectionMaxPoolSize()) +.setProtocolVersion(HttpVersion.HTTP_2) +.setHttp2ClearTextUpgrade(false) + .setTryUseCompression(TransportClientConfig.getConnectionCompression()); + +
[GitHub] heyile closed pull request #947: [SCB-837] make http2 production ready
heyile closed pull request #947: [SCB-837] make http2 production ready URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/947 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java index 98f5fd205..3fb9af337 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java @@ -19,6 +19,8 @@ import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultClientEndpointMetric; import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultClientEndpointMetricManager; import org.apache.servicecomb.foundation.vertx.metrics.metric.DefaultHttpSocketMetric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; @@ -34,6 +36,9 @@ */ public class DefaultHttpClientMetrics implements HttpClientMetrics { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHttpClientMetrics.class); + private final DefaultClientEndpointMetricManager clientEndpointMetricManager; private final HttpClient client; @@ -77,8 +82,9 @@ public void dequeueRequest(DefaultClientEndpointMetric endpointMetric, Object ta @Override public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) { -socketMetric.setEndpointMetric(endpointMetric); -endpointMetric.onConnect(); +// as http2 client will not invoke this method, the endpointMetric info will lost. +// you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660 +// hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName) } @Override @@ -133,7 +139,11 @@ public void disconnected(Object webSocketMetric) { @Override public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) { -return new DefaultHttpSocketMetric(null); +//we can get endpointMetric info here, so set the endpointMetric info directly +DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager +.getClientEndpointMetric(remoteAddress); +clientEndpointMetric.onConnect(); +return new DefaultHttpSocketMetric(clientEndpointMetric); } @Override diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java index 05f73a7f8..2ce5620fa 100644 --- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java +++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java @@ -61,9 +61,7 @@ public void init(Vertx vertx) throws Exception { HttpClientOptions httpClientOptions = createHttpClientOptions(); clientMgr = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptions)); -HttpClientOptions httpClientOptionshttp2 = createHttpClientOptions(); - httpClientOptionshttp2.setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2); -httpClientOptionshttp2.setHttp2ClearTextUpgrade(false); +HttpClientOptions httpClientOptionshttp2 = createHttp2ClientOptions(); clientMgrHttp2 = new ClientPoolManager<>(vertx, new HttpClientPoolFactory(httpClientOptionshttp2)); @@ -87,6 +85,21 @@ private static HttpClientOptions createHttpClientOptions() { return httpClientOptions; } + private static HttpClientOptions createHttp2ClientOptions() { +HttpClientOptions httpClientOptions = new HttpClientOptions(); + httpClientOptions.setMaxPoolSize(TransportClientConfig.getConnectionMaxPoolSize()) +.setUseAlpn(true) + .setIdleTimeout(TransportClientConfig.getConnectionIdleTimeoutInSeconds()) + .setHttp2MultiplexingLimit(TransportClientConfig.getHttp2MultiplexingLimit()) + .setHttp2MaxPoolSize(TransportClientConfig.getHttp2ConnectionMaxPoolSize()) +.setProtocolVersion(HttpVersion.HTTP_2) +.setHttp2ClearTextUpgrade(false) + .setTryUseCompression(TransportClientConfig.getConnectionCompression()); + +