Skip to content

Commit

Permalink
Merge pull request #24 from p0pr0ck5/msg_len
Browse files Browse the repository at this point in the history
optimization: dont calculate msg length more than necessary
  • Loading branch information
guanlan committed Apr 18, 2017
2 parents 76d3f46 + 002daa5 commit 15cc1c2
Showing 1 changed file with 8 additions and 8 deletions.
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

3 comments on commit 15cc1c2

@Sirandvwh
Copy link

Choose a reason for hiding this comment

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

Siradio Diallo [Siradio ](www.siradio.com) S624761798@d.()

@Sirandvwh
Copy link

Choose a reason for hiding this comment

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

Siradio Diallo [Siradio ](www.siradio.com) S624761798@d.()

@Sirandvwh
Copy link

Choose a reason for hiding this comment

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

#60

Please sign in to comment.