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

Adjust the read and write timeout configuration of the http server #2171

Closed
wants to merge 1 commit into from
Closed

Conversation

nic-6443
Copy link
Member

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

Adjust the read and write timeout configuration of the http server so that the Dashboard can work normally in a slow network environment. Especially write timeout, because the Dashboard has a relatively large front-end static resource file (>2M). When the bandwidth is limited It is easy to trigger the timeout in the scene, which will cause the page display to fail.

Related issues

fix/resolve #2165

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

… that the dashboard can work normally in a slow network environment.
@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #2171 (5b1e4c0) into master (a8298f4) will decrease coverage by 3.42%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2171      +/-   ##
==========================================
- Coverage   69.34%   65.92%   -3.43%     
==========================================
  Files         188      188              
  Lines        7161     7161              
  Branches      823      823              
==========================================
- Hits         4966     4721     -245     
- Misses       1906     2153     +247     
+ Partials      289      287       -2     
Flag Coverage Δ
backend-e2e-test 46.32% <50.00%> (-0.56%) ⬇️
backend-e2e-test-ginkgo ?
backend-unit-test 52.28% <ø> (-0.04%) ⬇️
frontend-e2e-test 68.21% <ø> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
api/internal/core/server/http.go 56.52% <50.00%> (ø)
api/internal/core/migrate/conflict.go 0.00% <0.00%> (-80.00%) ⬇️
api/internal/core/migrate/migrate.go 0.00% <0.00%> (-76.20%) ⬇️
api/internal/core/migrate/dataset.go 0.00% <0.00%> (-53.04%) ⬇️
api/internal/handler/migrate/migrate.go 8.06% <0.00%> (-51.62%) ⬇️
api/internal/utils/closer.go 33.33% <0.00%> (-33.34%) ⬇️
api/internal/handler/healthz/healthz.go 66.66% <0.00%> (-33.34%) ⬇️
api/internal/filter/schema.go 32.80% <0.00%> (-23.21%) ⬇️
api/internal/core/entity/entity.go 68.18% <0.00%> (-22.73%) ⬇️
api/internal/core/server/server.go 39.34% <0.00%> (-16.40%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8298f4...5b1e4c0. Read the comment docs.

@bzp2010
Copy link
Contributor

bzp2010 commented Oct 13, 2021

cc @nic-chen

@nic-chen
Copy link
Member

hi, @nic-6443 which file is so large?

@nic-6443
Copy link
Member Author

hi, @nic-6443 which file is so large?

The front-end static files from the /usr/local/apisix-dashboard/html/ directory. The largest file (p__Route__Create.8a1b69b7.async.js) has 2.1M. Under the current 5s timeout setting, this The transmission speed of the network is required to reach 430K/s, otherwise the file will fail to download.

image
When users deploy Dashboard on a public cloud, this problem will be easily triggered.

@zaunist
Copy link
Contributor

zaunist commented Oct 14, 2021

60 seconds seems a bit too long, can we compress the size of the JS file

@nic-chen
Copy link
Member

hi, @nic-6443 which file is so large?

The front-end static files from the /usr/local/apisix-dashboard/html/ directory. The largest file (p__Route__Create.8a1b69b7.async.js) has 2.1M. Under the current 5s timeout setting, this The transmission speed of the network is required to reach 430K/s, otherwise the file will fail to download.

image When users deploy Dashboard on a public cloud, this problem will be easily triggered.

hi, @bzp2010
Could we optimize the size of these files?
I remember there was a saying before, that a single file should be controlled within 100k to ensure user experience.
The internet speed is relatively high now, but a single file should not be that large.

@nic-6443
Copy link
Member Author

60s refers to the default value of send_timeout of nginx (although send_timeout is not for the transmission of the whole response).
I understand that WriteTimeout is used to prevent slow client attacks (Slowloris Attack), and Dashboard is usually not exposed to the public network , So I think there is no risk to increase WriteTimeout. Looking forward to your discussion.

@CGerAJ
Copy link

CGerAJ commented Oct 14, 2021

Should we add custom configuration timeouts? Allow low bandwidth users access, public network configuration can be limited to IP.

@nic-chen
Copy link
Member

Should we add custom configuration timeouts? Allow low bandwidth users access, public network configuration can be limited to IP.

@nic-6443 we could support configure them in conf/conf.yaml

@nic-6443
Copy link
Member Author

Should we add custom configuration timeouts? Allow low bandwidth users access, public network configuration can be limited to IP.

@nic-6443 we could support configure them in conf/conf.yaml

I think it's ok, but I still insist the default value can be larger so that users will not easily encounter problems when using it for the first time, just like me.Especially when there is no obvious risk of increasing timeout.

@zaunist
Copy link
Contributor

zaunist commented Oct 14, 2021

Should we add custom configuration timeouts? Allow low bandwidth users access, public network configuration can be limited to IP.

@nic-6443 we could support configure them in conf/conf.yaml

I think it's ok, but I still insist the default value can be larger so that users will not easily encounter problems when using it for the first time, just like me.Especially when there is no obvious risk of increasing timeout.

My advice is to consider how to compress js files first, and if there is no way to compress them, then discuss increasing the default timeout

@nic-6443
Copy link
Member Author

Should we add custom configuration timeouts? Allow low bandwidth users access, public network configuration can be limited to IP.

@nic-6443 we could support configure them in conf/conf.yaml

I think it's ok, but I still insist the default value can be larger so that users will not easily encounter problems when using it for the first time, just like me.Especially when there is no obvious risk of increasing timeout.

My advice is to consider how to compress js files first, and if there is no way to compress them, then discuss increasing the default timeout

ok, no problem

@bzp2010
Copy link
Contributor

bzp2010 commented Oct 15, 2021

I did some statistics. When you configure gzip for the server, the total file size will drop to less than 3MB. We can try it.

image

@starsz
Copy link
Contributor

starsz commented Oct 19, 2021

I did some statistics. When you configure gzip for the server, the total file size will drop to less than 3MB. We can try it.

image

That sounds good !

ReadTimeout: time.Duration(1000) * time.Millisecond,
WriteTimeout: time.Duration(5000) * time.Millisecond,
ReadTimeout: time.Duration(5000) * time.Millisecond,
WriteTimeout: time.Duration(60000) * time.Millisecond,
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to change the WriteTimeout here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be changed to add gzip middleware. It will greatly reduce the volume of transferred files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be changed to add gzip middleware. It will greatly reduce the volume of transferred files.

+1. And I'm happy to update the code.

@nic-6443 nic-6443 closed this Oct 19, 2021
@bzp2010
Copy link
Contributor

bzp2010 commented Oct 20, 2021

@nic-6443 Would you like to try using gin gzip middleware to solve the problem? If you don't have time to do it, I'll try to fix it.

@nic-6443
Copy link
Member Author

nic-6443 commented Oct 20, 2021

@nic-6443 Would you like to try using gin gzip middleware to solve the problem? If you don't have time to do it, I'll try to fix it.

I can do it, do I need a new pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP server write timeout value too small
7 participants