You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2012/01/19 23:42:29 UTC

svn commit: r1233620 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control: HttpMirrorControl.java HttpMirrorServer.java

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);
+            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);
         }
     }



Re: svn commit: r1233620 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control: HttpMirrorControl.java HttpMirrorServer.java

Posted by Philippe Mouawad <ph...@gmail.com>.
Hello sebb,
Commited.

Regards
Philippe

On Fri, Jan 20, 2012 at 1:19 AM, sebb <se...@gmail.com> wrote:

> On 19 January 2012 22:42,  <pm...@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);
> >         }
> >     }
> >
> >
>



-- 
Cordialement.
Philippe Mouawad.

Re: svn commit: r1233620 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control: HttpMirrorControl.java HttpMirrorServer.java

Posted by sebb <se...@gmail.com>.
On 19 January 2012 22:42,  <pm...@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);
>         }
>     }
>
>