On 19 January 2012 22:42,  <pmoua...@apache.org> wrote:
> Author: pmouawad
> Date: Thu Jan 19 22:42:29 2012
> New Revision: 1233620
>
> URL: http://svn.apache.org/viewvc?rev=1233620&view=rev
> Log:
> Bug 52471 - Improve Mirror Server performance by Using Pool of threads 
> instead of launching a Thread for each request
> Implemented what was described on dev list
>
> Modified:
>    
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorControl.java
>    
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java
>
> Modified: 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorControl.java
> URL: 
> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorControl.java?rev=1233620&r1=1233619&r2=1233620&view=diff
> ==============================================================================
> --- 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorControl.java
>  (original)
> +++ 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorControl.java
>  Thu Jan 19 22:42:29 2012
> @@ -44,7 +44,7 @@ public class HttpMirrorControl extends A
>
>     public static final String MAX_POOL_SIZE = 
> "HttpMirrorControlGui.maxPoolSize"; // $NON-NLS-1$
>
> -    public static final int DEFAULT_MAX_POOL_SIZE = 10;
> +    public static final int DEFAULT_MAX_POOL_SIZE = 0;
>
>     public HttpMirrorControl() {
>         initPort(DEFAULT_PORT);
>
> Modified: 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java
> URL: 
> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java?rev=1233620&r1=1233619&r2=1233620&view=diff
> ==============================================================================
> --- 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java
>  (original)
> +++ 
> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java
>  Thu Jan 19 22:42:29 2012
> @@ -94,13 +94,15 @@ public class HttpMirrorServer extends Th
>         except = null;
>         running = true;
>         ServerSocket mainSocket = null;
> -        final ArrayBlockingQueue<Runnable> queue = new 
> ArrayBlockingQueue<Runnable>(
> -                25);
> -        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
> -                maxThreadPoolSize/2,
> -                maxThreadPoolSize, KEEP_ALIVE_TIME, TimeUnit.SECONDS, queue);
> -        threadPoolExecutor.setRejectedExecutionHandler(new 
> ThreadPoolExecutor.DiscardOldestPolicy());
> -
> +        ThreadPoolExecutor threadPoolExecutor = null;
> +        if(maxThreadPoolSize>0) {
> +            final ArrayBlockingQueue<Runnable> queue = new 
> ArrayBlockingQueue<Runnable>(
> +                    25);

Why choose 25?
Should this not also be changeable?

> +            threadPoolExecutor = new ThreadPoolExecutor(
> +                    maxThreadPoolSize/2,
> +                    maxThreadPoolSize, KEEP_ALIVE_TIME, TimeUnit.SECONDS, 
> queue);
> +            threadPoolExecutor.setRejectedExecutionHandler(new 
> ThreadPoolExecutor.DiscardOldestPolicy());
> +        }
>         try {
>             log.info("Creating HttpMirror ... on port " + daemonPort);
>             mainSocket = new ServerSocket(daemonPort);
> @@ -112,10 +114,13 @@ public class HttpMirrorServer extends Th
>                     Socket clientSocket = mainSocket.accept();
>                     if (running) {
>                         // Pass request to new thread
> -                       threadPoolExecutor.execute(new 
> HttpMirrorThread(clientSocket));
> -                       //HttpMirrorThread thd = new 
> HttpMirrorThread(clientSocket);
> -                        log.debug("Starting new Mirror thread");
> -                        //thd.start();
> +                        if(threadPoolExecutor != null) {
> +                            threadPoolExecutor.execute(new 
> HttpMirrorThread(clientSocket));
> +                        } else {
> +                            Thread thd = new Thread(new 
> HttpMirrorThread(clientSocket));
> +                            log.debug("Starting new Mirror thread");
> +                            thd.start();
> +                        }
>                     } else {
>                         log.warn("Server not running");
>                         JOrphanUtils.closeQuietly(clientSocket);
> @@ -130,7 +135,9 @@ public class HttpMirrorServer extends Th
>             except = e;
>             log.warn("HttpMirror Server stopped", e);
>         } finally {
> -               threadPoolExecutor.shutdownNow();
> +            if(threadPoolExecutor != null) {
> +                threadPoolExecutor.shutdownNow();
> +            }
>             JOrphanUtils.closeQuietly(mainSocket);
>         }
>     }
>
>

Reply via email to