Skip to content

Commit

Permalink
http compression explained in doc
Browse files Browse the repository at this point in the history
Signed-off-by:Stefano Gargiulo <[email protected]>
  • Loading branch information
Stefano Gargiulo committed Nov 7, 2016
1 parent 854d0eb commit 5997b71
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/main/java/io/vertx/core/http/HttpServerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class HttpServerOptions extends NetServerOptions {
public static final boolean DEFAULT_COMPRESSION_SUPPORTED = false;

/**
* Default gzip compression level = 1, fastest
* Default gzip/deflate compression level = 1, fastest algorithm
*/
public static final int DEFAULT_COMPRESSION_LEVEL = 1;

Expand Down Expand Up @@ -342,16 +342,17 @@ public HttpServerOptions setOpenSslEngineOptions(OpenSSLEngineOptions sslEngineO
}

/**
* @return true if the server supports compression
* @return true if the server supports gzip/deflate compression
*/
public boolean isCompressionSupported() {
return compressionSupported;
}

/**
* Set whether the server supports compression
* Set whether the server should support gzip/deflate compression
* (serving compressed responses to clients advertising support for them with Accept-Encoding header)
*
* @param compressionSupported true if compression supported
* @param compressionSupported true to enable compression support
* @return a reference to this, so the API can be used fluently
*/
public HttpServerOptions setCompressionSupported(boolean compressionSupported) {
Expand All @@ -360,16 +361,38 @@ public HttpServerOptions setCompressionSupported(boolean compressionSupported) {
}

/**
* @return the server gzip compression level
*
* @return the server gzip/deflate 'compression level' to be used in responses when client and server support is turned on
*/
public int getCompressionLevel() {
return this.compressionLevel;
}

/**
* Set the compression level
*
* @param compressionLevel gzip compression level (1-9) - 1 is fastest, 9 the slower but size reducing savings

/**
* This method allows to set the compression level to be used in http1.x/2 response bodies
* when compression support is turned on (@see setCompressionSupported) and the client advertises
* to support deflate/gizip compression in the Accept-Encoding header
*
* default value is : 1
*
* The compression level determines how much the data is compressed on a scale from 1 to 9,
* where '9' is trying to achieve the maximum compression ratio while '1' instead is giving
* priority to speed instead of compression ratio using some algorithm optimizations and skipping
* pedantic loops that usually gives just little improvements
*
* While one can think that best value is always the maximum compression ratio,
* there's a trade-off to consider: the most compressed level requires the most
* computatinal work to compress/decompress data, e.g. more dictionary lookups and loops.
*
* E.g. you have it set fairly high on a high-volume website, you may experience performance degradation
* and latency on resource serving due to CPU overload, and homehower - as the comptational work is required also client side
* while decompressing - setting an higher compression level can result in an overall higher page load time
* especially nowadays when many clients are handled mobile devices with a low CPU profile.
*
* see also: http://www.gzip.org/algorithm.txt
*
* @param compressionLevel integer 1-9, 1 means use fastest algorithm, 9 slower algorithm but better compression ratio
* @return a reference to this, so the API can be used fluently
*/
public HttpServerOptions setCompressionLevel(int compressionLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ VertxHttp2ConnectionHandlerBuilder<C> useCompression(boolean useCompression) {
return this;
}

/**
* This method allows to set the compression level to be used in the http/2 connection encoder
* (for data sent to client) when compression support is turned on (@see useCompression) and
* the client advertises to support deflate/gizip compression in the Accept-Encoding header
*
* default value is : 1
*
* While one can think that best value is always the maximum compression ratio,
* there's a trade-off to consider: the most compressed level requires the most computatinal work to compress/decompress,
* E.g. you have it set fairly high on a high-volume website, you may experience performance degradation
* and latency on resource serving due to CPU overload, and homehower - as the comptational work is required also client side
* while decompressing - setting an higher compression level can result in an overall higher page load time
* especially nowadays when many clients are handled mobile devices with a low CPU profile.
*
* see also: http://www.gzip.org/algorithm.txt
*
* @param compressionLevel integer 1-9, 1 means use fastest algorithm, 9 slower algorithm but better compression ratio
* @return a reference to this instance for fulent API coding style
*/
VertxHttp2ConnectionHandlerBuilder<C> compressionLevel(int compressionLevel) {
this.compressionLevel = compressionLevel;
return this;
Expand Down

0 comments on commit 5997b71

Please sign in to comment.