@Bean
UndertowServletWebServerFactory undertowServletWebServerFactory() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addBuilderCustomizers(
builder -> {
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.setWorkerThreads(64)
.setIoThreads(25)
.setBufferSize(16384)
.setServerOption(UndertowOptions.HTTP2_SETTINGS_ENABLE_PUSH,true);
});
return factory;
}
@Bean
public okhttp3.OkHttpClient okHttpClient(@Value("${keypath}") String file,
@Value("${keypassword}") String password) throws KeyStoreException, IOException,
CertificateException, NoSuchAlgorithmException, KeyManagementException {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (FileInputStream instream = new FileInputStream(ResourceUtils.getFile(file))) {
trustStore.load(instream, password.toCharArray());
} catch (java.security.cert.CertificateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// X509TrustManager
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new TrustManager[] { trustManager }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(20));
dispatcher.setMaxRequests(maxTotal);
dispatcher.setMaxRequestsPerHost(maxPerRoute);
OkHttpClient.Builder builder = new OkHttpClient.Builder().
connectionPool(new ConnectionPool(100,15,TimeUnit.MINUTES)).
dispatcher(dispatcher).
protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1));
builder.sslSocketFactory(sslSocketFactory, trustManager);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
}
Also I have given this in the properties file:
server.undertow.worker-threads=64
server.undertow.io-threads=25
- OkHttp3 version: 4.9.1
- webserverlet: Undertow
Even though I added the worker-threads and io-threads on the server side either 5 or below 5 connections only getting added. Also the connection pool and dispatcher also not much helpful in this scenario.
I need to achieve more TPS (transactions per second).