You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shenyu.apache.org by "邪龙(dragon-zhang)" <19...@qq.com.INVALID> on 2022/04/25 04:38:51 UTC
回复: some bugfix and refactor for shenyu
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" <xiaoyu@apache.org>;
发送时间: 2022年4月25日(星期一) 上午10:36
收件人: "dev"<dev@shenyu.apache.org>;
主题: Re: some bugfix and refactor for shenyu
Hi
Looks good for me,
BTW,TcpClient#runOn` have better performance?
邪龙(dragon-zhang) <1936978077@qq.com.invalid> 于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