同等环境下,对于传输内容的压缩处理,对于TPS有倍数上的提升效率。

  1. 序列化前后对于传输内容的压缩和解压缩
  2. 基于业务类型来选择使用,业务类型按如下分类
    1. 强CPU
    2. 强IO
  3. 核心代码如下

  1. 压缩类型:
        QUICK_LZ_COMPRESSOR("quickLzCompressor"),
        SNAPPY_COMPRESSOR("snappyCompressor");
    
    public class CompressorExecutor {
        public static byte[] compress(byte[] bytes) {
            return compress(bytes, CompressorFactory.getCompressorType());
        }
    
        public static byte[] decompress(byte[] bytes) {
            return decompress(bytes, CompressorFactory.getCompressorType());
        }
    
        public static byte[] compress(byte[] bytes, CompressorType type) {
            if (type == CompressorType.QUICK_LZ_COMPRESSOR) {
                return QuickLz.compress(bytes, 1);
            } else if (type == CompressorType.SNAPPY_COMPRESSOR) {
                try {
                    return Snappy.compress(bytes);
                } catch (IOException e) {
                    throw new CompressorException(e);
                }
            } else {
                throw new CompressorException("Invalid compressor type : " + type);
            }
        }
    
        public static byte[] decompress(byte[] bytes, CompressorType type) {
            if (type == CompressorType.QUICK_LZ_COMPRESSOR) {
                return QuickLz.decompress(bytes);
            } else if (type == CompressorType.SNAPPY_COMPRESSOR) {
                try {
                    return Snappy.uncompress(bytes);
                } catch (IOException e) {
                    throw new CompressorException(e);
                }
            } else {
                throw new CompressorException("Invalid compressor type : " + type);
            }
        }
    

results matching ""

    No results matching ""