Skip to content

optimization: dont calculate msg length more than necessary #24

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

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/resty/logger/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ local function _flush_buffer()
end
end

local function _write_buffer(msg)
local function _write_buffer(msg, len)
log_buffer_index = log_buffer_index + 1
log_buffer_data[log_buffer_index] = msg

buffer_size = buffer_size + #msg
buffer_size = buffer_size + len


return buffer_size
Expand Down Expand Up @@ -505,28 +505,28 @@ function _M.log(msg)
msg = tostring(msg)
end

local msg_len = #msg

if (debug) then
ngx.update_time()
ngx_log(DEBUG, ngx.now(), ":log message length: " .. #msg)
ngx_log(DEBUG, ngx.now(), ":log message length: " .. msg_len)
end

local msg_len = #msg

-- response of "_flush_buffer" is not checked, because it writes
-- error buffer
if (is_exiting()) then
exiting = true
_write_buffer(msg)
_write_buffer(msg, msg_len)
_flush_buffer()
if (debug) then
ngx_log(DEBUG, "Nginx worker is exiting")
end
bytes = 0
elseif (msg_len + buffer_size < flush_limit) then
_write_buffer(msg)
_write_buffer(msg, msg_len)
bytes = msg_len
elseif (msg_len + buffer_size <= drop_limit) then
_write_buffer(msg)
_write_buffer(msg, msg_len)
_flush_buffer()
bytes = msg_len
else
Expand Down