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

Lazy evaluation when logging messages #1960

Merged
merged 5 commits into from Nov 19, 2018

Conversation

@terry-xiaoyu
Copy link
Contributor

terry-xiaoyu commented Nov 14, 2018

Formatting variables and then passing them into the logger functions leads
to performance issues. i.e.

logger:debug("RECV ~s", [emqx_packet:format(Packet)])

Above message will only be printed when the current log level set to
debug, but the function emqx_packet:format/1 will always be evaluated no
matter what the current log level is.

OTP 21 provides a special meta-data named report_cb, which can be used
for lazy evaluation. The fun is only evaluated if the primary/handler log level
check passes, and is therefore recommended if it is expensive to generate
the message.

Formatting variables and then passing them into the logger functions leads
to performance issues. i.e.

```erlang
logger:debug("RECV ~s", [emqx_packet:format(Packet)])
```

Above message will only be printed when the current log level set to
`debug`, but the function emqx_packet:format/1 will always be evaluated no
matter what the current log level is.

OTP 21 provides a special meta-data named `report_cb`, which can be used
for lazy evaluation. The fun is only evaluated if the primary/handler log level
check passes, and is therefore recommended if it is expensive to generate
the message.
@terry-xiaoyu terry-xiaoyu requested a review from gilbertwong96 Nov 14, 2018
@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 14, 2018

Pull Request Test Coverage Report for Build 3802

  • 16 of 47 (34.04%) changed or added relevant lines in 4 files are covered.
  • 29 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.6%) to 60.958%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/emqx_connection.erl 5 14 35.71%
src/emqx_ws_connection.erl 3 13 23.08%
src/emqx_protocol.erl 6 18 33.33%
Files with Coverage Reduction New Missed Lines %
src/emqx_protocol.erl 4 72.09%
src/emqx_packet.erl 25 44.58%
Totals Coverage Status
Change from base Build 3753: -0.6%
Covered Lines: 2723
Relevant Lines: 4467

💛 - Coveralls
src/emqx_connection.erl Outdated Show resolved Hide resolved
src/emqx_protocol.erl Outdated Show resolved Hide resolved
src/emqx_protocol.erl Show resolved Hide resolved
@terry-xiaoyu terry-xiaoyu requested a review from turtleDeng Nov 15, 2018
Copy link
Contributor

gilbertwong96 left a comment

Please add eunit tests or common tests for your new code to improve the coverage

include/logger.hrl Show resolved Hide resolved
include/logger.hrl Show resolved Hide resolved
src/emqx_connection.erl Outdated Show resolved Hide resolved
include/logger.hrl Outdated Show resolved Hide resolved
@turtleDeng turtleDeng merged commit bc1464a into emqx30 Nov 19, 2018
2 of 3 checks passed
2 of 3 checks passed
coverage/coveralls Coverage decreased (-0.6%) to 60.958%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@spring2maz spring2maz deleted the lazy_eval_in_logger branch Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.