Configuring for production

The Play Framework understands that applications may require changes in configuration prior to deployment in production. To simplify deploying, the command to deploy the application also accepts application-level configurations as arguments:

[PlayScala] $ start -Dapplication.secret=S3CR3T
[info] Wrote /PlayScala/target/scala-2.10/playscala_2.10-1.0.pom

(Starting server. Type Ctrl+D to exit logs, the server will remain in background)
 
Play server process ID is 14904

Let's change the application's HTTP port as follows:

#setting http port to 1234
[PlayScala] $ start -Dhttp.port=1234

In some projects, the production and development configuration are maintained in two separate files. We could either pass one or more configurations or a different file altogether. There are three ways of specifying a configuration file explicitly. It can be achieved by using one of the following options:

  • config.resource: This option is used when the file is within the class path (a file in application/conf)
  • config.file: This option is used when the file is available on the local filesystem but not bundled with the application's resources
  • config.url: This option is used when the file is to be loaded from a URL

Suppose our application uses conf/application-prod.conf in production, we can specify the file as follows:

[PlayScala] $ start -Dconfig.resource=application-prod.conf

Similarly, we can also modify the logger configuration by replacing the config key with logger:

[PlayScala] $ start -Dlogger.resource=logger-prod.xml

We can also configure the underlying Netty server by passing the settings as arguments and this not possible through application.conf. The following table lists some of the settings related to the server that can be configured in one or more ways.

The properties related to the address and port are as follows:

Property

Purpose

Default value

http.address

The address at which the application will be deployed

0.0.0.0

http.port

The port at which the application will be available

9000

https.port

The sslPort port at which the application will be available

 

The properties related to the HTTP requests (HttpRequestDecoder) are as follows:

Property

Purpose

Default value

http.netty.maxInitialLineLength

The maximum length of the initial line (for example, GET / HTTP/1.0)

4096

http.netty.maxHeaderSize

The maximum length of all the headers combined together

8192

http.netty.maxChunkSize

The maximum length of the body or each chunk of it. If the length of the body exceeds this value, the content will be split into chunks of this size or less (in case of the last one). If the request sends the chunked data and the length of a chunk exceeds this value, it will be split into smaller chunks.

8192

The properties related to the TCP socket options are shown in the following table:

Property

Purpose

Default

http.netty.option.backlog

The maximum size for queued incoming connections

 

http.netty.option.reuseAddress

Reuse address

 

http.netty.option.receiveBufferSize

The size of the socket that receives a buffer

 

http.netty.option.sendBufferSize

The size of the socket that sends a buffer

 

http.netty.option.child.keepAlive

Keeps connections alive

False

http.netty.option.child.soLinger

Lingers on closing if the data is present

Negative integer (disabled)

http.netty.option.tcpNoDelay

Disables Nagle's algorithm. TCP/IP uses an algorithm known as Nagle's algorithm to coalesce short segments and improve network efficiency.

False

http.netty.option.trafficClass

The Type of Service (ToS) octet in the Internet Protocol (IP) header.

0

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.103.96