Skip to content

Replace Http Compression (FramedLZ4CompressorOutputStream) #2273

Description

@mzitnik

Currently, HTTP Compression is done by using FramedLZ4CompressorOutputStream
There are more faster implementations on the market we can use them

Activity

  1. added
    legacy
    client
    on Apr 2, 2025
  2. simondaudin commented on Mar 24, 2026

    @simondaudin

    Hello, to second that, out of curiosity, I tried to use http compression for insertion, and I noticed a huge decrease in performance, like 100 x slower that internal lz4 compression.
    I ran a quick test to compare the compressor and check if I was imagining things or not.
    Here are the test and the results:

    public void insertFormatOutputStreamBench() throws Exception {
            Instant instant = Instant.parse("2025-01-23T22:00:35.00Z");
            Supplier<Stream<Object[]>> rows = () -> IntStream.range(0, 300).boxed()
                    .flatMap(c1 -> IntStream.range(0, 300).boxed()
                            .flatMap(c2 -> IntStream.range(0, 3).boxed()
                                    .map(c3 -> {
                                        long value = c1 + c2 + c3;
                                        return new Object[]{instant, "k1_v" + c1, "k2_v" + c2, "k3_v" + c3, value, value + 1, value + 2, value + 3};
                                    })));
    
            bench("FramedLZ4CompressorOutputStream", rows, out -> {
                try {
                    return new FramedLZ4CompressorOutputStream(out);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            bench("LZ4FrameOutputStream", rows, out -> {
                try {
                    return new LZ4FrameOutputStream(out);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            bench("ClickHouseLZ4OutputStream,", rows, out -> new ClickHouseLZ4OutputStream(out, LZ4Factory.fastestInstance().fastCompressor(), 65536));
        }
    
        private void bench(String name, Supplier<Stream<Object[]>> rows, UnaryOperator<OutputStream> writer) throws IOException {
            ByteArrayOutputStream target = new ByteArrayOutputStream();
            Stopwatch timer = Stopwatch.createStarted();
            try (OutputStream outputStream = writer.apply(target)) {
                rows.get().forEach(row -> {
                    try {
                        BinaryStreamUtils.writeDateTime(outputStream, LocalDateTime.ofInstant((Instant) row[0], ZoneOffset.UTC), TimeZone.getTimeZone("UTC"));
                        BinaryStreamUtils.writeString(outputStream, (String) row[1]);
                        BinaryStreamUtils.writeString(outputStream, (String) row[2]);
                        BinaryStreamUtils.writeString(outputStream, (String) row[3]);
                        BinaryStreamUtils.writeUnsignedInt64(outputStream, (Long) row[4]);
                        BinaryStreamUtils.writeUnsignedInt64(outputStream, (Long) row[5]);
                        BinaryStreamUtils.writeUnsignedInt64(outputStream, (Long) row[6]);
                        BinaryStreamUtils.writeUnsignedInt64(outputStream, (Long) row[7]);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                });
            }
            System.out.printf("%s took %d ms, produced %d bytes %n", name,
                    timer.elapsed(TimeUnit.MILLISECONDS), target.size());
        }
    
    FramedLZ4CompressorOutputStream took 17687 ms, produced 1844286 bytes 
    LZ4FrameOutputStream took 189 ms, produced 2702992 bytes 
    ClickHouseLZ4OutputStream, took 117 ms, produced 2576610 bytes 
    

    In this state, it seems that FramedLZ4CompressorOutputStream is not really usable for insertion

  3. chernser commented on Oct 1, 2026

    @chernser
    Contributor

    @mzitnik @simondaudin
    This is because HTTP compressed is backed by Apache Compress that uses LZ77 own implementation instead of lz4-java with JNI support.
    Insert will be fixed. Query need more code changes because lz4-java doesn't support dependent blocks in current version (or I'm doing something wrong)

  4. added this to the 0.11.0 milestone on Oct 1, 2026
  5. added
    jdbc
    connectivity
    and removed
    legacy
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clientconnectivityenhancementjdbcperformance

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions