Hi, xiaoyu, thanks for response. Under my local stress test, `HttpClient` can
reach about 2500 QPS without thread pool configuration:
```java
@Bean
public HttpClient httpClient(final HttpClientProperties
properties) {
HttpClientProperties.Pool pool =
properties.getPool();
ConnectionProvider connectionProvider =
buildConnectionProvider(pool);
HttpClient httpClient =
HttpClient.create(connectionProvider)
.tcpConfiguration(tcpClient -> {
if
(Objects.nonNull(properties.getConnectTimeout())) {
tcpClient = tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
properties.getConnectTimeout());
}
HttpClientProperties.Proxy proxy = properties.getProxy();
if
(StringUtils.isNotEmpty(proxy.getHost())) {
tcpClient = setTcpClientProxy(tcpClient, proxy);
}
tcpClient
= tcpClient.doOnConnected(connection -> {
connection.addHandlerLast(new
IdleStateHandler(properties.getReaderIdleTime(),
properties.getWriterIdleTime(), properties.getAllIdleTime(),
TimeUnit.MILLISECONDS));
connection.addHandlerLast(new
WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new
ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
});
//here not config
return
tcpClient;
});
HttpClientProperties.Ssl ssl = properties.getSsl();
if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
||
ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
||
ssl.isUseInsecureTrustManager()) {
httpClient =
httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
}
if (properties.isWiretap()) {
httpClient = httpClient.wiretap(true);
}
return
httpClient.keepAlive(properties.isKeepAlive());
}
```
And about 2600 QPS after configuration:
```java
@Bean
public HttpClient httpClient(final HttpClientProperties
properties,
final ObjectProvider<LoopResources>
provider) {
HttpClientProperties.Pool pool =
properties.getPool();
ConnectionProvider connectionProvider =
buildConnectionProvider(pool);
HttpClient httpClient =
HttpClient.create(connectionProvider)
.tcpConfiguration(tcpClient -> {
if
(Objects.nonNull(properties.getConnectTimeout())) {
tcpClient = tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
properties.getConnectTimeout());
}
HttpClientProperties.Proxy proxy = properties.getProxy();
if
(StringUtils.isNotEmpty(proxy.getHost())) {
tcpClient = setTcpClientProxy(tcpClient, proxy);
}
tcpClient
= tcpClient.doOnConnected(connection -> {
connection.addHandlerLast(new
IdleStateHandler(properties.getReaderIdleTime(),
properties.getWriterIdleTime(), properties.getAllIdleTime(),
TimeUnit.MILLISECONDS));
connection.addHandlerLast(new
WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new
ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
});
//add the config here
final
LoopResources loopResources = provider.getIfAvailable();
if
(Objects.nonNull(loopResources)) {
tcpClient = tcpClient.runOn(loopResources);
}
return
tcpClient;
});
HttpClientProperties.Ssl ssl = properties.getSsl();
if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
||
ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
||
ssl.isUseInsecureTrustManager()) {
httpClient =
httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
}
if (properties.isWiretap()) {
httpClient = httpClient.wiretap(true);
}
return
httpClient.keepAlive(properties.isKeepAlive());
}
```
------------------ ???????? ------------------
??????:
"dev"
<[email protected]>;
????????: 2022??4??25??(??????) ????10:36
??????: "dev"<[email protected]>;
????: Re: some bugfix and refactor for shenyu
Hi
Looks good for me??
BTW??TcpClient#runOn` have better performance?
????(dragon-zhang) <[email protected]> ??2022??4??24??????
21:32??????
>
> Dear community:
>
> PR[1] use `TcpClient#runOn` and configure
`DefaultLoopResources`&nbsp;as a singleton bean, and finally fixes ISSUE[2]
correctly. I'm sorry for the previous wrong submission;
>
>
> PR[3] refactor part of the logic of `ShenyuThreadPoolExecutor` to make it
more extensible, and fixed a previous bug(see `workQueue.setExecutor(this);`
line in `ShenyuThreadPoolExecutor`);
>
>
> Now `MemoryLimitCalculator#maxAvailable` will call JNI every time to get
the latest JVM memory information, PR [4] adjusts it to get it every 50ms;
>
>
> If you are free, please see the PR[1], PR[3], PR[4] and help these PRs to
be better.
>
> Looking forward to your reply.
>
> [1]&nbsp;https://github.com/apache/incubator-shenyu/pull/3314
> [2]&nbsp;https://github.com/apache/incubator-shenyu/issues/3063
> [3]&nbsp;https://github.com/apache/incubator-shenyu/pull/3315
> [4]&nbsp;https://github.com/apache/incubator-shenyu/pull/3316