Support for configuring number of worker threads in undertow
This commit is contained in:
parent
de774a3058
commit
b6fd58e644
6 changed files with 46 additions and 31 deletions
|
@ -59,6 +59,7 @@ public class KeycloakServer {
|
|||
public static class KeycloakServerConfig {
|
||||
private String host = "localhost";
|
||||
private int port = 8081;
|
||||
private int workerThreads = Math.max(Runtime.getRuntime().availableProcessors(), 2) * 8;
|
||||
private String resourcesHome;
|
||||
|
||||
public String getHost() {
|
||||
|
@ -84,6 +85,14 @@ public class KeycloakServer {
|
|||
public void setResourcesHome(String resourcesHome) {
|
||||
this.resourcesHome = resourcesHome;
|
||||
}
|
||||
|
||||
public int getWorkerThreads() {
|
||||
return workerThreads;
|
||||
}
|
||||
|
||||
public void setWorkerThreads(int workerThreads) {
|
||||
this.workerThreads = workerThreads;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T loadJson(InputStream is, Class<T> type) {
|
||||
|
@ -141,6 +150,10 @@ public class KeycloakServer {
|
|||
config.setResourcesHome(dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (System.getProperties().containsKey("undertowWorkerThreads")) {
|
||||
int undertowWorkerThreads = Integer.parseInt(System.getProperty("undertowWorkerThreads"));
|
||||
config.setWorkerThreads(undertowWorkerThreads);
|
||||
}
|
||||
|
||||
final KeycloakServer keycloak = new KeycloakServer(config);
|
||||
keycloak.sysout = true;
|
||||
|
@ -244,7 +257,10 @@ public class KeycloakServer {
|
|||
ResteasyDeployment deployment = new ResteasyDeployment();
|
||||
deployment.setApplicationClass(KeycloakApplication.class.getName());
|
||||
|
||||
Builder builder = Undertow.builder().addListener(config.getPort(), config.getHost());
|
||||
Builder builder = Undertow.builder()
|
||||
.addHttpListener(config.getPort(), config.getHost())
|
||||
.setWorkerThreads(config.getWorkerThreads())
|
||||
.setIoThreads(config.getWorkerThreads() / 8);
|
||||
|
||||
server = new UndertowJaxrsServer().start(builder);
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.undertow.server.handlers.resource.ClassPathResourceManager;
|
|||
import io.undertow.servlet.Servlets;
|
||||
import io.undertow.servlet.api.DeploymentInfo;
|
||||
import io.undertow.servlet.api.FilterInfo;
|
||||
import io.undertow.servlet.api.MimeMapping;
|
||||
import io.undertow.servlet.api.ServletInfo;
|
||||
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
|
||||
import org.jboss.resteasy.spi.ResteasyDeployment;
|
||||
|
@ -28,7 +27,7 @@ public class KeycloakPerfServer {
|
|||
KeycloakServer keycloakServer = KeycloakServer.bootstrapKeycloakServer(args);
|
||||
System.out.println("Keycloak server bootstrapped");
|
||||
|
||||
ProviderSessionFactoryHolder.setProviderSessionFactory(keycloakServer.getProviderSessionFactory());
|
||||
KeycloakSessionFactoryHolder.setKeycloakSessionFactory(keycloakServer.getSessionFactory());
|
||||
new KeycloakPerfServer(keycloakServer).start();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.keycloak.testsuite.performance.web;
|
||||
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
|
||||
/**
|
||||
* Static holder to allow sharing ProviderSessionFactory among different JAX-RS applications
|
||||
*
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class KeycloakSessionFactoryHolder {
|
||||
|
||||
private static KeycloakSessionFactory keycloakSessionFactory;
|
||||
|
||||
public static KeycloakSessionFactory getKeycloakSessionFactory() {
|
||||
return keycloakSessionFactory;
|
||||
}
|
||||
|
||||
public static void setKeycloakSessionFactory(KeycloakSessionFactory keycloakSessionFactory) {
|
||||
KeycloakSessionFactoryHolder.keycloakSessionFactory = keycloakSessionFactory;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import javax.ws.rs.core.Application;
|
|||
import javax.ws.rs.core.Context;
|
||||
|
||||
import org.jboss.resteasy.core.Dispatcher;
|
||||
import org.keycloak.provider.ProviderSessionFactory;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.test.tools.PerfTools;
|
||||
|
||||
/**
|
||||
|
@ -18,14 +18,14 @@ import org.keycloak.test.tools.PerfTools;
|
|||
*/
|
||||
public class KeycloakToolsApplication extends Application {
|
||||
|
||||
protected ProviderSessionFactory providerSessionFactory;
|
||||
protected KeycloakSessionFactory keycloakSessionFactory;
|
||||
protected Set<Class<?>> classes = new HashSet<Class<?>>();
|
||||
protected Set<Object> singletons = new HashSet<Object>();
|
||||
|
||||
public KeycloakToolsApplication(@Context ServletContext context, @Context Dispatcher dispatcher) {
|
||||
this.providerSessionFactory = ProviderSessionFactoryHolder.getProviderSessionFactory();
|
||||
context.setAttribute(ProviderSessionFactory.class.getName(), this.providerSessionFactory);
|
||||
singletons.add(new PerfTools(providerSessionFactory));
|
||||
this.keycloakSessionFactory = KeycloakSessionFactoryHolder.getKeycloakSessionFactory();
|
||||
context.setAttribute(KeycloakSessionFactory.class.getName(), this.keycloakSessionFactory);
|
||||
singletons.add(new PerfTools(keycloakSessionFactory));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package org.keycloak.testsuite.performance.web;
|
||||
|
||||
import org.keycloak.provider.ProviderSessionFactory;
|
||||
|
||||
/**
|
||||
* Static holder to allow sharing ProviderSessionFactory among different JAX-RS applications
|
||||
*
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class ProviderSessionFactoryHolder {
|
||||
|
||||
private static ProviderSessionFactory providerSessionFactory;
|
||||
|
||||
public static ProviderSessionFactory getProviderSessionFactory() {
|
||||
return providerSessionFactory;
|
||||
}
|
||||
|
||||
public static void setProviderSessionFactory(ProviderSessionFactory providerSessionFactory) {
|
||||
ProviderSessionFactoryHolder.providerSessionFactory = providerSessionFactory;
|
||||
}
|
||||
}
|
|
@ -113,9 +113,9 @@ public class PerfTools {
|
|||
// Same as createUsers, but dynamically compute "start" (Next available user)
|
||||
@GET
|
||||
@Path("{realm}/create-available-users")
|
||||
public Response createAvailableUsers(@PathParam("realm") String realmName, @QueryParam("count") Integer count, @QueryParam("batch") Integer batch, @QueryParam("prefix") String prefix, @QueryParam("roles") String roles) throws InterruptedException {
|
||||
public void createAvailableUsers(@PathParam("realm") String realmName, @QueryParam("count") Integer count, @QueryParam("batch") Integer batch, @QueryParam("prefix") String prefix, @QueryParam("roles") String roles) throws InterruptedException {
|
||||
int start = getUsersCount(realmName, prefix);
|
||||
return createUsers(realmName, count, batch, start, prefix, roles);
|
||||
createUsers(realmName, count, batch, start, prefix, roles);
|
||||
}
|
||||
|
||||
private int getUsersCount(String realmName, String prefix) {
|
||||
|
|
Loading…
Reference in a new issue