try Jackson compression impact, #24155

* increased the default compress-larger-than to 32 KiB,
  because gzip performance overhead
* support 'off' config value to disable completely
This commit is contained in:
Patrik Nordwall 2019-06-02 20:02:27 +02:00
parent 381cb1c5d3
commit 467d65043e
3 changed files with 14 additions and 6 deletions

View file

@ -288,7 +288,8 @@ than the following configuration are compressed with GZIP.
@@snip [reference.conf](/akka-serialization-jackson/src/main/resources/reference.conf) { #compression }
TODO: The binary formats are currently also compressed. That may change since it might not be needed for those.
Compression can be disabled by setting this configuration property to `off`. It will still be able to decompress
payloads that were compressed when serialized, e.g. if this configuration is changed.
## Additional configuration

View file

@ -27,7 +27,8 @@ akka.serialization.jackson {
#//#compression
akka.serialization.jackson {
# The serializer will compress the payload when it's larger than this value.
compress-larger-than = 10 KiB
# Compression can be disabled with value 'off'.
compress-larger-than = 32 KiB
}
#//#compression

View file

@ -22,6 +22,7 @@ import akka.event.Logging
import akka.serialization.BaseSerializer
import akka.serialization.SerializationExtension
import akka.serialization.SerializerWithStringManifest
import akka.util.Helpers.toRootLowerCase
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.jsontype.impl.SubTypeValidator
import com.fasterxml.jackson.dataformat.cbor.CBORFactory
@ -141,7 +142,13 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory
private val conf = JacksonObjectMapperProvider.configForBinding(bindingName, system.settings.config)
private val isDebugEnabled = conf.getBoolean("verbose-debug-logging") && log.isDebugEnabled
private final val BufferSize = 1024 * 4
private val compressLargerThan: Long = conf.getBytes("compress-larger-than")
private val compressLargerThan: Long = {
val key = "compress-larger-than"
toRootLowerCase(conf.getString(key)) match {
case "off" => Long.MaxValue
case _ => conf.getBytes(key)
}
}
private val migrations: Map[String, JacksonMigration] = {
import scala.collection.JavaConverters._
conf.getConfig("migrations").root.unwrapped.asScala.toMap.map {
@ -175,7 +182,6 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory
checkAllowedSerializationBindings()
val startTime = if (isDebugEnabled) System.nanoTime else 0L
val bytes = objectMapper.writeValueAsBytes(obj)
// FIXME investigate if compression should be used for the binary formats
val result =
if (bytes.length > compressLargerThan) compress(bytes)
else bytes
@ -254,8 +260,8 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory
"Deserialization of [{}] took [{}] µs, compressed size [{}] bytes, uncompressed size [{}] bytes",
clazz.getName,
durationMicros,
decompressBytes.length,
bytes.length)
bytes.length,
decompressBytes.length)
}
result