On 15 January 2012 22:27, <[email protected]> wrote: > Author: pmouawad > Date: Sun Jan 15 22:27:37 2012 > New Revision: 1231777 > > URL: http://svn.apache.org/viewvc?rev=1231777&view=rev > Log: > Bug 52471 - Improve Mirror Server performance by Using Pool of threads > instead of launching a Thread for each request
Does this still work when launching the mirror server from the batch file? What happens if the max_pool_size is exceeded? > Modified: > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > > 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 > > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorThread.java > > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpMirrorControlGui.java > jmeter/trunk/xdocs/changes.xml > > Modified: > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1231777&r1=1231776&r2=1231777&view=diff > ============================================================================== > --- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > (original) > +++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sun > Jan 15 22:27:37 2012 > @@ -333,6 +333,8 @@ http_response_code=HTTP response code > http_url_rewriting_modifier_title=HTTP URL Re-writing Modifier > http_user_parameter_modifier=HTTP User Parameter Modifier > httpmirror_title=HTTP Mirror Server > +httpmirror_settings=Settings > +httpmirror_max_pool_size=Max number of Threads: > id_prefix=ID Prefix > id_suffix=ID Suffix > if_controller_evaluate_all=Evaluate for all children? > @@ -640,6 +642,7 @@ proxy_content_type_filter=Content-type f > proxy_content_type_include=Include\: > proxy_daemon_bind_error=Could not create proxy - port in use. Choose another > port. > proxy_daemon_error=Could not create proxy - see log for details > +proxy_general_settings=Global Settings > proxy_headers=Capture HTTP Headers > proxy_httpsspoofing=Attempt HTTPS Spoofing > proxy_httpsspoofing_match=Only spoof URLs matching: > > Modified: > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1231777&r1=1231776&r2=1231777&view=diff > ============================================================================== > --- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > (original) > +++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > Sun Jan 15 22:27:37 2012 > @@ -327,6 +327,8 @@ http_response_code=Code de r\u00E9ponse > http_url_rewriting_modifier_title=Transcripteur d'URL HTTP > http_user_parameter_modifier=Modificateur de param\u00E8tre utilisateur HTTP > httpmirror_title=Serveur HTTP miroir > +httpmirror_settings=Param\u00E8tres > +httpmirror_max_pool_size=Nombre maximum de Threads: > id_prefix=Pr\u00E9fixe d'ID > id_suffix=Suffixe d'ID > if_controller_evaluate_all=Evaluer pour tous les fils ? > @@ -637,6 +639,7 @@ proxy_daemon_error=Impossible de lancer > proxy_headers=Capturer les ent\u00EAtes HTTP > proxy_httpsspoofing=Tenter d'usurper le HTTPS > proxy_httpsspoofing_match=Filtre d'URL pour usurpation HTTPS (regexp) \: > +proxy_general_settings=Param\u00E8tres g\u00E9n\u00E9raux > proxy_regex=Correspondance des variables par regex ? > proxy_sampler_settings=Param\u00E8tres Echantillon HTTP > proxy_sampler_type=Type \: > > 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=1231777&r1=1231776&r2=1231777&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 > Sun Jan 15 22:27:37 2012 > @@ -42,6 +42,10 @@ public class HttpMirrorControl extends A > > public static final String PORT = "HttpMirrorControlGui.port"; // > $NON-NLS-1$ > > + public static final String MAX_POOL_SIZE = > "HttpMirrorControlGui.maxPoolSize"; // $NON-NLS-1$ > + > + public static final int DEFAULT_MAX_POOL_SIZE = 10; > + > public HttpMirrorControl() { > initPort(DEFAULT_PORT); > } > @@ -69,13 +73,31 @@ public class HttpMirrorControl extends A > public String getPortString() { > return getPropertyAsString(PORT); > } > + > + /** > + * @return Max Pool Size > + */ > + public String getMaxPoolSizeAsString() { > + return getPropertyAsString(MAX_POOL_SIZE); > + } > + > + private int getMaxPoolSize() { > + return getPropertyAsInt(MAX_POOL_SIZE, DEFAULT_MAX_POOL_SIZE); > + } > + > + /** > + * @param maxPoolSize Max Thread Pool size > + */ > + public void setMaxPoolSize(String maxPoolSize) { > + setProperty(MAX_POOL_SIZE, maxPoolSize); > + } > > public int getDefaultPort() { > return DEFAULT_PORT; > } > > public void startHttpMirror() { > - server = new HttpMirrorServer(getPort()); > + server = new HttpMirrorServer(getPort(), getMaxPoolSize()); > server.start(); > GuiPackage instance = GuiPackage.getInstance(); > if (instance != null) { > > 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=1231777&r1=1231776&r2=1231777&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 > Sun Jan 15 22:27:37 2012 > @@ -21,6 +21,9 @@ package org.apache.jmeter.protocol.http. > import java.io.InterruptedIOException; > import java.net.ServerSocket; > import java.net.Socket; > +import java.util.concurrent.ArrayBlockingQueue; > +import java.util.concurrent.ThreadPoolExecutor; > +import java.util.concurrent.TimeUnit; > > import org.apache.jmeter.gui.Stoppable; > import org.apache.jorphan.logging.LoggingManager; > @@ -44,6 +47,8 @@ public class HttpMirrorServer extends Th > */ > private static final int ACCEPT_TIMEOUT = 1000; > > + private static final long KEEP_ALIVE_TIME = 10; > + > /** The port to listen on. */ > private final int daemonPort; > > @@ -54,14 +59,30 @@ public class HttpMirrorServer extends Th > private volatile Exception except; > > /** > + * Max Executor Pool size > + */ > + private int maxThreadPoolSize; > + > + /** > * Create a new Daemon with the specified port and target. > * > * @param port > * the port to listen on. > */ > public HttpMirrorServer(int port) { > + this(port, HttpMirrorControl.DEFAULT_MAX_POOL_SIZE); > + } > + > + /** > + * Create a new Daemon with the specified port and target. > + * > + * @param port > + * the port to listen on. > + */ > + public HttpMirrorServer(int port, int maxThreadPoolSize) { > super("HttpMirrorServer"); > this.daemonPort = port; > + this.maxThreadPoolSize = maxThreadPoolSize; > } > > /** > @@ -73,22 +94,28 @@ 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()); > > try { > log.info("Creating HttpMirror ... on port " + daemonPort); > mainSocket = new ServerSocket(daemonPort); > mainSocket.setSoTimeout(ACCEPT_TIMEOUT); > log.info("HttpMirror up and running!"); > - > while (running) { > try { > // Listen on main socket > Socket clientSocket = mainSocket.accept(); > if (running) { > // Pass request to new thread > - HttpMirrorThread thd = new > HttpMirrorThread(clientSocket); > + threadPoolExecutor.execute(new > HttpMirrorThread(clientSocket)); > + //HttpMirrorThread thd = new > HttpMirrorThread(clientSocket); > log.debug("Starting new Mirror thread"); > - thd.start(); > + //thd.start(); > } else { > log.warn("Server not running"); > JOrphanUtils.closeQuietly(clientSocket); > @@ -103,6 +130,7 @@ public class HttpMirrorServer extends Th > except = e; > log.warn("HttpMirror Server stopped", e); > } finally { > + threadPoolExecutor.shutdownNow(); > JOrphanUtils.closeQuietly(mainSocket); > } > } > > Modified: > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorThread.java > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorThread.java?rev=1231777&r1=1231776&r2=1231777&view=diff > ============================================================================== > --- > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorThread.java > (original) > +++ > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HttpMirrorThread.java > Sun Jan 15 22:27:37 2012 > @@ -38,7 +38,7 @@ import org.apache.oro.text.regex.Perl5Ma > * Thread to handle one client request. Gets the request from the client and > * sends the response back to the client. > */ > -public class HttpMirrorThread extends Thread { > +public class HttpMirrorThread implements Runnable { > private static final Logger log = LoggingManager.getLoggerForClass(); > > private static final String ISO_8859_1 = "ISO-8859-1"; //$NON-NLS-1$ > @@ -54,7 +54,6 @@ public class HttpMirrorThread extends Th > /** > * Main processing method for the HttpMirror object > */ > - @Override > public void run() { > log.debug("Starting thread"); > BufferedInputStream in = null; > > Modified: > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpMirrorControlGui.java > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpMirrorControlGui.java?rev=1231777&r1=1231776&r2=1231777&view=diff > ============================================================================== > --- > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpMirrorControlGui.java > (original) > +++ > jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpMirrorControlGui.java > Sun Jan 15 22:27:37 2012 > @@ -24,6 +24,7 @@ import java.awt.event.ActionListener; > import java.util.Arrays; > import java.util.Collection; > > +import javax.swing.BorderFactory; > import javax.swing.Box; > import javax.swing.JButton; > import javax.swing.JLabel; > @@ -50,6 +51,8 @@ public class HttpMirrorControlGui extend > > private JTextField portField; > > + private JTextField maxPoolSizeField; > + > private JButton stop, start; > > private static final String ACTION_STOP = "stop"; // $NON-NLS-1$ > @@ -58,6 +61,7 @@ public class HttpMirrorControlGui extend > > private HttpMirrorControl mirrorController; > > + > public HttpMirrorControlGui() { > super(); > log.debug("Creating HttpMirrorControlGui"); > @@ -83,6 +87,7 @@ public class HttpMirrorControlGui extend > if (el instanceof HttpMirrorControl) { > mirrorController = (HttpMirrorControl) el; > mirrorController.setPort(portField.getText()); > + mirrorController.setMaxPoolSize(maxPoolSizeField.getText()); > } > } > > @@ -102,6 +107,7 @@ public class HttpMirrorControlGui extend > super.configure(element); > mirrorController = (HttpMirrorControl) element; > portField.setText(mirrorController.getPortString()); > + maxPoolSizeField.setText(mirrorController.getMaxPoolSizeAsString()); > repaint(); > } > > @@ -163,10 +169,22 @@ public class HttpMirrorControlGui extend > label.setLabelFor(portField); > > > + maxPoolSizeField = new > JTextField(Integer.toString(HttpMirrorControl.DEFAULT_MAX_POOL_SIZE), 10); > + maxPoolSizeField.setName(HttpMirrorControl.PORT); > + > + JLabel mpsLabel = new > JLabel(JMeterUtils.getResString("httpmirror_max_pool_size")); // $NON-NLS-1$ > + mpsLabel.setLabelFor(maxPoolSizeField); > + > HorizontalPanel panel = new HorizontalPanel(); > + > panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), > + JMeterUtils.getResString("httpmirror_settings"))); // > $NON-NLS-1$ > + > panel.add(label); > panel.add(portField); > > + panel.add(mpsLabel); > + panel.add(maxPoolSizeField); > + > panel.add(Box.createHorizontalStrut(10)); > > return panel; > @@ -176,5 +194,6 @@ public class HttpMirrorControlGui extend > public void clearGui(){ > super.clearGui(); > portField.setText(HttpMirrorControl.DEFAULT_PORT_S); > + > maxPoolSizeField.setText(Integer.toString(HttpMirrorControl.DEFAULT_MAX_POOL_SIZE)); > } > } > \ No newline at end of file > > Modified: jmeter/trunk/xdocs/changes.xml > URL: > http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1231777&r1=1231776&r2=1231777&view=diff > ============================================================================== > --- jmeter/trunk/xdocs/changes.xml (original) > +++ jmeter/trunk/xdocs/changes.xml Sun Jan 15 22:27:37 2012 > @@ -260,6 +260,7 @@ Loads any additional properties found in > <li>Bug 52333 - Reduce overhead in calculating > SampleResult#nanoTimeOffset</li> > <li>Bug 52346 - Shutdown detects if there are any non-daemon threads left > which prevent JVM exit.</li> > <li>Bug 52281 - Support for file Drag and Drop</li> > +<li>Bug 52471 - Improve Mirror Server performance by Using Pool of threads > instead of launching a Thread for each request</li> > </ul> > > <h2>Non-functional changes</h2> > >
