Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0c9015fd
Commit
0c9015fd
authored
Oct 10, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6571 from herau:master
* pr/6571: Polish contribution Manage Tomcat queued connections
parents
d5b2f67b
ab2a2579
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
0 deletions
+95
-0
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+64
-0
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+29
-0
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+2
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
0c9015fd
...
...
@@ -86,6 +86,7 @@ import org.springframework.util.StringUtils;
* @author Eddú Meléndez
* @author Quinten De Swaef
* @author Venil Noronha
* @author Aurélien Leboulanger
*/
@ConfigurationProperties
(
prefix
=
"server"
,
ignoreUnknownFields
=
true
)
public
class
ServerProperties
...
...
@@ -656,6 +657,19 @@ public class ServerProperties
*/
private
Charset
uriEncoding
;
/**
* Maximum number of connections that the server will accept and process
* at any given time. Once the limit has been reached, the operating system
* may still accept connections based on the "acceptCount" property.
*/
private
int
maxConnections
=
0
;
/**
* Maximum queue length for incoming connection requests when all possible
* request processing threads are in use.
*/
private
int
acceptCount
=
0
;
public
int
getMaxThreads
()
{
return
this
.
maxThreads
;
}
...
...
@@ -748,6 +762,22 @@ public class ServerProperties
this
.
uriEncoding
=
uriEncoding
;
}
public
int
getMaxConnections
()
{
return
this
.
maxConnections
;
}
public
void
setMaxConnections
(
int
maxConnections
)
{
this
.
maxConnections
=
maxConnections
;
}
public
int
getAcceptCount
()
{
return
this
.
acceptCount
;
}
public
void
setAcceptCount
(
int
acceptCount
)
{
this
.
acceptCount
=
acceptCount
;
}
void
customizeTomcat
(
ServerProperties
serverProperties
,
TomcatEmbeddedServletContainerFactory
factory
)
{
if
(
getBasedir
()
!=
null
)
{
...
...
@@ -782,6 +812,40 @@ public class ServerProperties
if
(
this
.
redirectContextRoot
!=
null
)
{
customizeRedirectContextRoot
(
factory
,
this
.
redirectContextRoot
);
}
if
(
this
.
maxConnections
>
0
)
{
customizeMaxConnections
(
factory
);
}
if
(
this
.
acceptCount
>
0
)
{
customizeAcceptCount
(
factory
);
}
}
private
void
customizeAcceptCount
(
TomcatEmbeddedServletContainerFactory
factory
)
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
@Override
public
void
customize
(
Connector
connector
)
{
ProtocolHandler
handler
=
connector
.
getProtocolHandler
();
if
(
handler
instanceof
AbstractProtocol
)
{
AbstractProtocol
protocol
=
(
AbstractProtocol
)
handler
;
protocol
.
setBacklog
(
Tomcat
.
this
.
acceptCount
);
}
}
});
}
private
void
customizeMaxConnections
(
TomcatEmbeddedServletContainerFactory
factory
)
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
@Override
public
void
customize
(
Connector
connector
)
{
ProtocolHandler
handler
=
connector
.
getProtocolHandler
();
if
(
handler
instanceof
AbstractProtocol
)
{
AbstractProtocol
protocol
=
(
AbstractProtocol
)
handler
;
protocol
.
setMaxConnections
(
Tomcat
.
this
.
maxConnections
);
}
}
});
}
private
void
customizeConnectionTimeout
(
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
0c9015fd
...
...
@@ -32,6 +32,7 @@ import javax.servlet.SessionTrackingMode;
import
org.apache.catalina.Context
;
import
org.apache.catalina.Valve
;
import
org.apache.catalina.valves.RemoteIpValve
;
import
org.apache.coyote.AbstractProtocol
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.ArgumentCaptor
;
...
...
@@ -435,6 +436,34 @@ public class ServerPropertiesTests {
assertThat
(
remoteIpValve
.
getInternalProxies
()).
isEqualTo
(
"192.168.0.1"
);
}
@Test
public
void
customTomcatAcceptCount
()
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.accept-count"
,
"10"
);
bindProperties
(
map
);
TomcatEmbeddedServletContainerFactory
container
=
new
TomcatEmbeddedServletContainerFactory
();
this
.
properties
.
customize
(
container
);
TomcatEmbeddedServletContainer
embeddedContainer
=
(
TomcatEmbeddedServletContainer
)
container
.
getEmbeddedServletContainer
();
assertThat
(((
AbstractProtocol
)
embeddedContainer
.
getTomcat
().
getConnector
()
.
getProtocolHandler
()).
getBacklog
()).
isEqualTo
(
10
);
}
@Test
public
void
customTomcatMaxConnections
()
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.tomcat.max-connections"
,
"5"
);
bindProperties
(
map
);
TomcatEmbeddedServletContainerFactory
container
=
new
TomcatEmbeddedServletContainerFactory
();
this
.
properties
.
customize
(
container
);
TomcatEmbeddedServletContainer
embeddedContainer
=
(
TomcatEmbeddedServletContainer
)
container
.
getEmbeddedServletContainer
();
assertThat
(((
AbstractProtocol
)
embeddedContainer
.
getTomcat
().
getConnector
()
.
getProtocolHandler
()).
getMaxConnections
()).
isEqualTo
(
5
);
}
@Test
public
void
defaultUseForwardHeadersUndertow
()
throws
Exception
{
UndertowEmbeddedServletContainerFactory
container
=
spy
(
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
0c9015fd
...
...
@@ -193,6 +193,7 @@ content into your application; rather pick only the properties that you need.
server.ssl.trust-store-password= # Password used to access the trust store.
server.ssl.trust-store-provider= # Provider for the trust store.
server.ssl.trust-store-type= # Type of the trust store.
server.tomcat.accept-count= # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
...
...
@@ -208,6 +209,7 @@ content into your application; rather pick only the properties that you need.
172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
server.tomcat.max-threads=0 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment