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

feat: zstd-compress requests over 1MB #559

Merged
merged 5 commits into from
Dec 6, 2024
Merged

Conversation

jmoralez
Copy link
Member

@jmoralez jmoralez commented Dec 5, 2024

Automatically compresses payloads over 1MB using zstandard. This should help reduce the time when sending large payloads over slow internet connections.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

github-actions bot commented Dec 5, 2024

Experiment Results

Experiment 1: air-passengers

Description:

variable experiment
h 12
season_length 12
freq MS
level None
n_windows 1

Results:

metric timegpt-1 timegpt-1-long-horizon SeasonalNaive Naive
mae 12.6793 11.0623 47.8333 76
mape 0.027 0.0232 0.0999 0.1425
mse 213.936 199.132 2571.33 10604.2
total_time 2.0717 2.3661 0.0044 0.0035

Plot:

Experiment 2: air-passengers

Description:

variable experiment
h 24
season_length 12
freq MS
level None
n_windows 1

Results:

metric timegpt-1 timegpt-1-long-horizon SeasonalNaive Naive
mae 58.1031 58.4587 71.25 115.25
mape 0.1257 0.1267 0.1552 0.2358
mse 4040.21 4110.79 5928.17 18859.2
total_time 0.9389 1.5045 0.0046 0.0034

Plot:

Experiment 3: electricity-multiple-series

Description:

variable experiment
h 24
season_length 24
freq H
level None
n_windows 1

Results:

metric timegpt-1 timegpt-1-long-horizon SeasonalNaive Naive
mae 178.293 268.13 269.23 1331.02
mape 0.0234 0.0311 0.0304 0.1692
mse 121589 219485 213677 4.68961e+06
total_time 1.3746 2.9085 0.0047 0.0045

Plot:

Experiment 4: electricity-multiple-series

Description:

variable experiment
h 168
season_length 24
freq H
level None
n_windows 1

Results:

metric timegpt-1 timegpt-1-long-horizon SeasonalNaive Naive
mae 465.497 346.972 398.956 1119.26
mape 0.062 0.0436 0.0512 0.1583
mse 835021 403760 656723 3.17316e+06
total_time 0.8512 0.4568 0.0052 0.0046

Plot:

Experiment 5: electricity-multiple-series

Description:

variable experiment
h 336
season_length 24
freq H
level None
n_windows 1

Results:

metric timegpt-1 timegpt-1-long-horizon SeasonalNaive Naive
mae 558.673 459.757 602.926 1340.95
mape 0.0697 0.0565 0.0787 0.17
mse 1.22723e+06 739114 1.61572e+06 6.04619e+06
total_time 0.5684 1.1687 0.0052 0.005

Plot:

@jmoralez jmoralez changed the title feat: zstd-compress requests over 10MB feat: zstd-compress requests over 1MB Dec 5, 2024
@jmoralez jmoralez marked this pull request as ready for review December 5, 2024 19:11
@jmoralez jmoralez requested a review from AzulGarza December 5, 2024 19:11
setup.py Outdated
@@ -48,6 +48,7 @@
"tenacity",
"tqdm",
"utilsforecast>=0.2.8",
"zstandard",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also set httpx[zstd] to ensure correct version is installed?

Copy link
Member Author

Choose a reason for hiding this comment

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

That'd be if we were getting zstd-compressed responses.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh it seems httpx automatically adds accept-encoding: 'zstd' to the headers if zstandard is installed and modal automatically compresses the responses when it sees this, so it's indeed worth adding. Thanks!

@@ -42,8 +42,7 @@
python_requires=">=3.9",
install_requires=[
"annotated-types",
"coreforecast>=0.0.14",
Copy link
Member Author

Choose a reason for hiding this comment

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

This was added in a bad merge in #547

" httpx.Client = original_client\n",
"\n",
"# this produces a 1MB payload\n",
"series = generate_series(250, n_static_features=2)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it only compresses above 1 mb? So a 1 mb payload shouldn't compress?

Copy link
Contributor

@elephaint elephaint left a comment

Choose a reason for hiding this comment

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

LGTM, two insignificant comments:

  • Test is with 1 MB but I thought the idea that it doesn't compress up to (and including) 1 MB?
  • Out of curiosity why 1MB as threshold?

@jmoralez
Copy link
Member Author

jmoralez commented Dec 6, 2024

I meant over 1MB in the comment, it's just slightly above it.

The threshold is because at 1MB it takes around 1ms to compress and it's most likely worth it due to the savings in bandwidth, since it always compresses to less than half the original size.

@jmoralez jmoralez merged commit 761e246 into main Dec 6, 2024
12 checks passed
@jmoralez jmoralez deleted the zstd-req-compression branch December 6, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants