Skip to content

Commit 04b1676

Browse files
author
freynaud
committed
Fix #6772 adding a configuration parameter to set the number of thread jetty uses.
Default = -1 = current behavior ( 255 thread from Jetty's default settings )
1 parent 16da8dc commit 04b1676

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

java/server/src/org/openqa/grid/common/defaults/DefaultHub.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"cleanUpCycle": 5000,
1212
"timeout": 300000,
1313
"browserTimeout": 0,
14-
"maxSession": 5
14+
"maxSession": 5,
15+
"jettyMaxThreads":-1
1516
}

java/server/src/org/openqa/grid/internal/utils/GridHubConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public class GridHubConfiguration {
9999
*/
100100
private String logFilename;
101101

102+
/**
103+
* max number of thread for Jetty. Default is normally 255.
104+
*/
105+
private int jettyMaxThreads = -1;
102106
/**
103107
* to specify that logging level should be set to Level.DEBUG
104108
*/
@@ -113,6 +117,7 @@ public class GridHubConfiguration {
113117
private String grid1Yml = null;
114118
private String grid2JSON = null;
115119

120+
116121
public GridHubConfiguration() {
117122
loadDefault();
118123
}
@@ -180,6 +185,9 @@ public void loadFromCommandLine(String[] args) {
180185
if (helper.isParamPresent("-port")) {
181186
port = Integer.parseInt(helper.getParamValue("-port"));
182187
}
188+
if (helper.isParamPresent("-jettyMaxThreads")) {
189+
jettyMaxThreads = Integer.parseInt(helper.getParamValue("-jettyMaxThreads"));
190+
}
183191
if (helper.isParamPresent("-cleanUpCycle")) {
184192
cleanupCycle = Integer.parseInt(helper.getParamValue("-cleanUpCycle"));
185193
}
@@ -306,6 +314,9 @@ public void loadFromJSON(String resource) {
306314
servlets.add(jsservlets.getString(i));
307315
}
308316
}
317+
if (o.has("jettyMaxThreads") && !o.isNull("jettyMaxThreads")) {
318+
jettyMaxThreads = o.getInt("jettyMaxThreads");
319+
}
309320
if (o.has("prioritizer") && !o.isNull("prioritizer")) {
310321
String prioritizerClass = o.getString("prioritizer");
311322
setPrioritizer(prioritizerClass);
@@ -516,4 +527,7 @@ public Map<String, Object> getAllParams() {
516527
return allParams;
517528
}
518529

530+
public int getJettyMaxThreads() {
531+
return jettyMaxThreads;
532+
}
519533
}

java/server/src/org/openqa/grid/web/Hub.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.seleniumhq.jetty7.server.Server;
3737
import org.seleniumhq.jetty7.server.bio.SocketConnector;
3838
import org.seleniumhq.jetty7.servlet.ServletContextHandler;
39+
import org.seleniumhq.jetty7.util.thread.QueuedThreadPool;
3940

4041
import java.net.MalformedURLException;
4142
import java.net.URL;
@@ -54,6 +55,7 @@ public class Hub {
5455

5556
private final int port;
5657
private final String host;
58+
private final int maxThread;
5759
private final boolean isHostRestricted;
5860
private final Registry registry;
5961
private final Map<String, Class<? extends Servlet>> extraServlet = Maps.newHashMap();
@@ -76,6 +78,8 @@ public Registry getRegistry() {
7678
public Hub(GridHubConfiguration config) {
7779
registry = Registry.newInstance(this, config);
7880

81+
maxThread = config.getJettyMaxThreads();
82+
7983
if (config.getHost() != null) {
8084
host = config.getHost();
8185
isHostRestricted = true;
@@ -161,6 +165,11 @@ public String getHost() {
161165
public void start() throws Exception {
162166
initServer();
163167
server.start();
168+
if (maxThread>0){
169+
QueuedThreadPool pool = new QueuedThreadPool();
170+
pool.setMaxThreads(maxThread);
171+
server.setThreadPool(pool);
172+
}
164173
}
165174

166175
public void stop() throws Exception {

0 commit comments

Comments
 (0)