美文网首页
SNAPPY ZLIB LZ4 Gzip几个压缩算法的对比

SNAPPY ZLIB LZ4 Gzip几个压缩算法的对比

作者: 大地缸 | 来源:发表于2021-03-08 18:53 被阅读0次

title: "SNAPPY ZLIB LZ4 Gzip几个压缩算法的对比"
date: 2021-02-17T20:29:13+08:00
draft: true
tags: ['snappy']
author: "dadigang"
author_cn: "大地缸"
personal: "http://www.real007.cn"


关于作者

http://www.real007.cn/about

SNAPPY,ZLIB,LZ4,gzip几个压缩算法的对比

以下是各种压缩方式下,应用服务器的性能数据

场景 响应时间 QPS CPU 网络带宽(out) GC数目

====================================================================

压缩:无 | 21.6ms 11500 81 118m 0

压缩:SNAPPY | 28ms 9900 77 111m 19

压缩:ZLIB | 25ms 10000 78 112m 27

压缩:LZ4 | 23ms 10900 78 110m 0

压缩:gzip | 30ms 9900 78 113m 44

下面是用本地机器做的对比:

deflater,gzip,lz4,snappy各项对比如下:

压缩比:

source byte size: 2974090

snappy byte size: 499280

gzip byte size: 383723

deflater byte size: 463823

lz4 byte size: 170805

性能比:

name Mode Cnt ScoreError Unitsdeflaterthrpt20≈ 10^-4ops/usgzipthrpt20≈ 10^-5ops/uslz4thrpt20≈ 10^-3ops/ussnappythrpt20≈ 10^-4ops/usdeflateravgt20 30595.443 ± 3117.520us/opgzipavgt20 79238.541 ± 7208.015us/oplz4avgt203149.854 ± 395.372us/opsnappyavgt20 11257.427 ± 1219.347us/opdeflatersample431 47889.938 ± 826.705us/opdeflater:deflater·p0.00sample36700.16us/opdeflater:deflater·p0.50sample46989.312us/opdeflater:deflater·p0.90sample53202.125us/opdeflater:deflater·p0.95sample55351.706us/opdeflater:deflater·p0.99sample68073.554us/opdeflater:deflater·p0.999sample81788.928us/opdeflater:deflater·p0.9999sample81788.928us/opdeflater:deflater·p1.00sample81788.928us/opgzipsample22293336.844 ± 1869.349us/opgzip:gzip·p0.00sample72089.6us/opgzip:gzip·p0.50sample94044.16us/opgzip:gzip·p0.90sample100545.331us/opgzip:gzip·p0.95sample107026.842us/opgzip:gzip·p0.99sample118761.718us/opgzip:gzip·p0.999sample128450.56us/opgzip:gzip·p0.9999sample128450.56us/opgzip:gzip·p1.00sample128450.56us/oplz4sample54193866.797 ± 54.781us/oplz4:lz4·p0.00sample2082.816us/oplz4:lz4·p0.50sample4009.984us/oplz4:lz4·p0.90sample4530.176us/oplz4:lz4·p0.95sample4980.736us/oplz4:lz4·p0.99sample6859.981us/oplz4:lz4·p0.999sample22632.202us/oplz4:lz4·p0.9999sample32178.176us/oplz4:lz4·p1.00sample32178.176us/opsnappysample177511473.738 ± 189.907us/opsnappy:snappy·p0.00sample6299.648us/opsnappy:snappy·p0.50sample11665.408us/opsnappy:snappy·p0.90sample12900.762us/opsnappy:snappy·p0.95sample14139.392us/opsnappy:snappy·p0.99sample17627.873us/opsnappy:snappy·p0.999sample56448.516us/opsnappy:snappy·p0.9999sample59703.296us/opsnappy:snappy·p1.00sample59703.296us/opdeflaterss2049073.148 ± 4697.407us/opgzipss20108874.516 ± 9298.844us/oplz4ss207779.001 ± 4453.597us/opsnappyss2011424.403 ± 2107.730us/op

注:

Mode标注:

thrpt:Throughput: operations per unit of time.

(Runs by continuously calling methods, counting the total throughput over all worker threads. This mode is time-based, and it will run until the iteration time expires.)

avgt:Average time: average time per per operation.

(Runs by continuously calling methods, counting the average time to call over all worker threads. This is the inverse of , but with different aggregation policy. This mode is time-based, and it will run until the iteration time expires.)

sample:Sample time: samples the time for each operation.

(Runs by continuously calling methods, and randomly samples the time needed for the call. This mode automatically adjusts the sampling frequency, but may omit some pauses which missed the sampling measurement. This mode is time-based, and it will run until the iteration time expires.)

ss:Single shot time: measures the time for a single operation.

(Runs by calling once and measuring its time. This mode is useful to estimate the "cold" performance when you don't want to hide the warmup invocations, or if you want to see the progress from call to call, or you want to record every single sample. This mode is work-based, and will run only for a single invocation of method.)

注意:lz4使用的是LZ4Factory.fastestJavaInstance().fastCompressor(),如果用fastestInstance而不是fastestJavaInstance的时候也会使用Native通过JNI实现

      deflater使用的是Deflater(Deflater.BEST\_SPEED)模式

lz4在压缩比上完胜

lz4在首次初始化速度上完胜,

lz4在速度上完胜

lz4在稳定性上完胜

但是lz4的解压比较麻烦,需要指定原byte数组大小,所以开发起来工作量要大些,但是它性能好压缩比高啊。

相关文章

网友评论

      本文标题:SNAPPY ZLIB LZ4 Gzip几个压缩算法的对比

      本文链接:https://www.haomeiwen.com/subject/jjawfltx.html