users@grizzly.java.net

RE: Concurrent connections using Grizzly/Jersey

From: Vivek Malik <bird_sky_at_hotmail.com>
Date: Fri, 21 Oct 2011 06:48:24 +0000

Answering my own email. We were able to fix it and scale to 50 worker threads by using the following code snippet
GrizzlyWebServer grizzlyWebServer = new GrizzlyWebServer(8080);grizzlyWebServer.getSelectorThread().setMaxKeepAliveRequests(0);grizzlyWebServer.setCoreThreads(30);grizzlyWebServer.setMaxThreads(50);ServletAdapter jerseyAdapter = new ServletAdapter();jerseyAdapter.addInitParameter("com.sun.jersey.config.property.packages", "com.test");jerseyAdapter.setServletInstance(new ServletContainer());grizzlyWebServer.addGrizzlyAdapter(jerseyAdapter, new String[]{"/"});grizzlyWebServer.start();
Please let me know if we can embed grizzly while using jersey in a better way.
Thanks,Vivek

> To: users_at_grizzly.java.net
> From: bird_sky_at_hotmail.com
> Subject: Concurrent connections using Grizzly/Jersey
> Date: Thu, 20 Oct 2011 21:18:11 +0000
>
> Hi,
>
> We are embedding Grizzly in our code and are facing concurrent
> connections in production. We are unable to scale beyond 7-8 concurrent
> requests. I believe the problem lies in the way we are using Grizzly
> and appreciate any help you can offer. I am able to replicate the
> problem with the following sample code.
>
> Please suggest what we are doing wrong and how can we use grizzly to
> scale up to many more concurrent requests.
>
> ==========Main.java==========
> import com.sun.grizzly.http.SelectorThread;
> import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
> import java.io.IOException;
> import java.util.HashMap;
> import java.util.Map;
> public class Main {
> public static void main(String[] args) throws InterruptedException
> {
> Map<String, String> initParams=new HashMap<String, String>();
> initParams.put("com.sun.jersey.config.property.packages",
> "com.test");
> try {
> SelectorThread threadSelector =
> GrizzlyWebContainerFactory.create("http://localhost:8080/",
> initParams);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
> ========Default.java=========
> package com.test;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
>
> @Path("{path:.*}")
> public class Default {
> @GET
> @Produces( "text/plain" )
> public String getMessage() {
> try {
> // Adding sleep to simulate some background processing
> Thread.sleep(1000);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> return "Hello World";
> }
> }
> =========================