Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Change zlib compression level #47387

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Oct 2, 2023

This was flate.HuffmanOnly (-2) to 6 to match what MySQL does.

Note that compress/flate doesn't define a const for level 6.

What problem does this PR solve?

Issue Number: close #47278

Problem Summary:

Related: #36780

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

The compression level for zlib level was updated to match the compression level of MySQL

This was `flate.HuffmanOnly` (-2) to 6 to match what MySQL does.

Note that `compress/flate` doesn't define a const for level 6.
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 2, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 2, 2023
@dveeden
Copy link
Contributor Author

dveeden commented Oct 2, 2023

With this patch:

diff --git a/server/internal/packetio.go b/server/internal/packetio.go
index e015c0ce08..2ffbf5ed7f 100644
--- a/server/internal/packetio.go
+++ b/server/internal/packetio.go
@@ -381,12 +381,13 @@ func (cw *compressedWriter) Flush() error {
        // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_compression_packet.html
        // suggests a MIN_COMPRESS_LENGTH of 50.
        minCompressLength := 50
+       zlibCompressDefaultLevel := 6
        data := cw.buf.Bytes()
        cw.buf.Reset()
 
        switch cw.compressionAlgorithm {
        case mysql.CompressionZlib:
-               w, err = zlib.NewWriterLevel(&payload, zlib.HuffmanOnly)
+               w, err = zlib.NewWriterLevel(&payload, zlibCompressDefaultLevel)
        case mysql.CompressionZstd:
                w, err = zstd.NewWriter(&payload, zstd.WithEncoderLevel(cw.zstdLevel))
        default:

Patched (165 bytes compressed, 2065 uncompressed):
image

Original (411 bytes compressed, 2065 uncompressed):
image

@ti-chi-bot ti-chi-bot bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 2, 2023
@tiprow
Copy link

tiprow bot commented Oct 2, 2023

Hi @dveeden. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dveeden dveeden requested a review from djshow832 October 2, 2023 14:02
@dveeden
Copy link
Contributor Author

dveeden commented Oct 2, 2023

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Oct 2, 2023
@dveeden
Copy link
Contributor Author

dveeden commented Oct 2, 2023

/test all

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Merging #47387 (9b4f551) into master (95378e5) will increase coverage by 0.3942%.
The diff coverage is 100.0000%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #47387        +/-   ##
================================================
+ Coverage   72.3183%   72.7125%   +0.3942%     
================================================
  Files          1352       1373        +21     
  Lines        400846     407184      +6338     
================================================
+ Hits         289885     296074      +6189     
- Misses        91782      92333       +551     
+ Partials      19179      18777       -402     
Flag Coverage Δ
integration 38.5068% <0.0000%> (?)
unit 72.3193% <100.0000%> (+0.0010%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser 84.7544% <ø> (ø)
br 48.7512% <ø> (-4.3470%) ⬇️

@dveeden
Copy link
Contributor Author

dveeden commented Oct 2, 2023

/test all

@dveeden dveeden marked this pull request as ready for review October 2, 2023 20:45
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 2, 2023
@dveeden
Copy link
Contributor Author

dveeden commented Oct 3, 2023

/retest

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the result of 16M SQL as the issue described?

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 3, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 3, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, lance6716

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [hawkingrei,lance6716]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 3, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 3, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-10-03 14:31:44.771488195 +0000 UTC m=+544302.358598324: ☑️ agreed by lance6716.
  • 2023-10-03 17:18:19.401414729 +0000 UTC m=+554296.988524859: ☑️ agreed by hawkingrei.

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot merged commit ddee0a5 into pingcap:master Oct 3, 2023
14 of 16 checks passed
@@ -381,12 +381,13 @@ func (cw *compressedWriter) Flush() error {
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_compression_packet.html
// suggests a MIN_COMPRESS_LENGTH of 50.
minCompressLength := 50
zlibCompressDefaultLevel := 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "6" here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is MySQL's choice #47278 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The compression ratio of TiDB is much worse than MySQL
4 participants