-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
perf(tools): yield when gzip or gunzip #13338
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
local buffer = require "string.buffer" | ||
local zlib = require "ffi-zlib" | ||
local yield = require("kong.tools.yield").yield | ||
|
||
|
||
local inflate_gzip = zlib.inflateGzip | ||
|
@@ -15,7 +16,16 @@ local GZIP_CHUNK_SIZE = 65535 | |
|
||
|
||
local function read_input_buffer(input_buffer) | ||
local count = 0 | ||
local yield_size = GZIP_CHUNK_SIZE * 2 | ||
|
||
return function(size) | ||
count = count + size | ||
if count > yield_size then | ||
count = 0 | ||
yield() | ||
end | ||
|
||
local data = input_buffer:get(size) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking whether Because according to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently (in kong gatway), we are using gzip/gunzip only for string data (CP/DP config), so far as I know no socket to be applied to gzip/gunzip. |
||
return data ~= "" and data or nil | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any consideration to yield for
2 GZIP_CHUNK_SIZE
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have enough data to support this number, so
GZIP_CHUNK_SIZE * 2
is just a estimated value.