Quantcast

It's very hard to increase the number of worker threads in Jersey-Grizzly module.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

It's very hard to increase the number of worker threads in Jersey-Grizzly module.

George Cao
I use jersey 1.12 right now and i experienced a server non-response
case recently after the server was started for a while. Then i dig into
this, and find out that some of my API take too long to connect to
another service server due to the broken network.

And the same time,  the server runs very slow, seems like cannot accept
any new connection. Actually all the  worker threads are busying
waiting. The default number of the worker thread is
Runtime.getRuntime().availableProcessors() * 2 = 4 on my box. So i want
to increase this number.

The only way to accomplish this i found so far is to  override
createHttpServer method in GrizzlyServerFactory, the override the
default value before starting the server. But GrizzlyServerFactory has
a final class modifier, so i copy all the code into a new class in
order to do this.

Is there any config options beside this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: It's very hard to increase the number of worker threads in Jersey-Grizzly module.

Oleksiy Stashok-2
Hi,

---------------------------------------------------
// create HTTP server
HttpServer server = GrizzlyServerFactory.createHttpServer(....);

// create the thread pool configuration
ThreadPoolConfig config = ThreadPoolConfig.newConfig().
                                         setPoolName("mypool").
                                         setCorePoolSize(10).
                                         setMaxPoolSize(300);

// assign the thread pool
NetworkListener listener = httpServer.getListeners().iterator().next();
listener.getTransport().setWorkerThreadPoolConfig(config);
---------------------------------------------------

* depending on Grizzly version ThreadPoolConfig instance might be created via ThreadPoolConfig.defaultConfig()....

WBR,
Alexey.

On 05/29/2012 08:14 PM, [hidden email] wrote:
I use jersey 1.12 right now and i experienced a server non-response
case recently after the server was started for a while. Then i dig into
this, and find out that some of my API take too long to connect to
another service server due to the broken network. 

And the same time,  the server runs very slow, seems like cannot accept
any new connection. Actually all the  worker threads are busying
waiting. The default number of the worker thread is
Runtime.getRuntime().availableProcessors() * 2 = 4 on my box. So i want
to increase this number. 

The only way to accomplish this i found so far is to  override
createHttpServer method in GrizzlyServerFactory, the override the
default value before starting the server. But GrizzlyServerFactory has
a final class modifier, so i copy all the code into a new class in
order to do this.

Is there any config options beside this? 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: It's very hard to increase the number of worker threads in Jersey-Grizzly module.

Marcel Büsch
In reply to this post by George Cao
That doesn't work, after the Server is started:

I checked with this example:

        int testPort = AvailablePortFinder.getNextAvailable(1024);
        HttpServer server =
GrizzlyServerFactory.createHttpServer("http://localhost:" +   testPort,
new DefaultResourceConfig(Resource.class));

// create the thread pool configuration
        ThreadPoolConfig config = createThreadConfig(poolName);

        // assign the thread pool
        NetworkListener listener =
server.getListeners().iterator().next();
        log.info("NetworListener Name " + listener.getName());
        final TCPNIOTransport tcpnioTransport =
listener.getTransport();
        tcpnioTransport.setWorkerThreadPoolConfig(config);
        final ThreadPoolConfig real =
tcpnioTransport.getWorkerThreadPoolConfig();
        if (config.getCorePoolSize() != real.getCorePoolSize())
log.info("CorePoolSize is not set. Should be :" +
config.getCorePoolSize() + " but is :" + real.getCorePoolSize());
        if (config.getMaxPoolSize() != real.getMaxPoolSize())
log.info("MaxPoolSize is not set. Should be :" +
config.getMaxPoolSize() + " but is :" + real.getMaxPoolSize());
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: It's very hard to increase the number of worker threads in Jersey-Grizzly module.

Oleksiy Stashok-2
Oh, if server has been started - then we have to reconfigure the active worker thread pool.

---------------------------------------------------
// create HTTP server
HttpServer server = GrizzlyServerFactory.createHttpServer(....);

// create the thread pool configuration
ThreadPoolConfig config = ThreadPoolConfig.newConfig().
                                         setPoolName("mypool").
                                         setCorePoolSize(10).
                                         setMaxPoolSize(300);

// reconfigure the thread pool
NetworkListener listener = httpServer.getListeners().iterator().next();
GrizzlyExecutorService threadPool = (GrizzlyExecutorService) listener.getTransport().getWorkerThreadPool()
;
threadPool.reconfigure(config);


WBR,
Alexey.

On 05/31/2012 11:18 AM, [hidden email] wrote:
That doesn't work, after the Server is started:

I checked with this example:

	int testPort = AvailablePortFinder.getNextAvailable(1024);
	HttpServer server =
GrizzlyServerFactory.createHttpServer("http://localhost:" +   testPort,
new DefaultResourceConfig(Resource.class));

// create the thread pool configuration
	ThreadPoolConfig config = createThreadConfig(poolName);

	// assign the thread pool
	NetworkListener listener =
server.getListeners().iterator().next();
	log.info("NetworListener Name " + listener.getName());
	final TCPNIOTransport tcpnioTransport =
listener.getTransport();
	tcpnioTransport.setWorkerThreadPoolConfig(config);
	final ThreadPoolConfig real =
tcpnioTransport.getWorkerThreadPoolConfig();
	if (config.getCorePoolSize() != real.getCorePoolSize())
log.info("CorePoolSize is not set. Should be :" +
config.getCorePoolSize() + " but is :" + real.getCorePoolSize());
	if (config.getMaxPoolSize() != real.getMaxPoolSize())
log.info("MaxPoolSize is not set. Should be :" +
config.getMaxPoolSize() + " but is :" + real.getMaxPoolSize());

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: It's very hard to increase the number of worker threads in Jersey-Grizzly module.

George Cao
These solutions work, but need developers learn by themselves. And usually there are many conceptions new to the developers, this make the situation worse.

To figure out the solution, beside googling, one need to understand these and how they work. And this is poorly documented.

I saw some Builders, Factories class ,  but they are hidden in depth, not exposed to developers. I just feel not good and worried about if i can solve problems in the future as soon as possible.

2012/5/31 Oleksiy Stashok <[hidden email]>
Oh, if server has been started - then we have to reconfigure the active worker thread pool.

---------------------------------------------------
// create HTTP server
HttpServer server = GrizzlyServerFactory.createHttpServer(....);

// create the thread pool configuration
ThreadPoolConfig config = ThreadPoolConfig.newConfig().
                                         setPoolName("mypool").
                                         setCorePoolSize(10).
                                         setMaxPoolSize(300);

// reconfigure the thread pool
NetworkListener listener = httpServer.getListeners().iterator().next();
GrizzlyExecutorService threadPool = (GrizzlyExecutorService) listener.getTransport().getWorkerThreadPool()
;
threadPool.reconfigure(config);


WBR,
Alexey.


On 05/31/2012 11:18 AM, [hidden email] wrote:
That doesn't work, after the Server is started:

I checked with this example:

	int testPort = AvailablePortFinder.getNextAvailable(1024);
	HttpServer server =
GrizzlyServerFactory.createHttpServer("http://localhost:" +   testPort,
new DefaultResourceConfig(Resource.class));

// create the thread pool configuration
	ThreadPoolConfig config = createThreadConfig(poolName);

	// assign the thread pool
	NetworkListener listener =
server.getListeners().iterator().next();
	log.info("NetworListener Name " + listener.getName());
	final TCPNIOTransport tcpnioTransport =
listener.getTransport();
	tcpnioTransport.setWorkerThreadPoolConfig(config);
	final ThreadPoolConfig real =
tcpnioTransport.getWorkerThreadPoolConfig();
	if (config.getCorePoolSize() != real.getCorePoolSize())
log.info("CorePoolSize is not set. Should be :" +
config.getCorePoolSize() + " but is :" + real.getCorePoolSize());
	if (config.getMaxPoolSize() != real.getMaxPoolSize())
log.info("MaxPoolSize is not set. Should be :" +
config.getMaxPoolSize() + " but is :" + real.getMaxPoolSize());


Loading...