[
https://issues.apache.org/jira/browse/METRON-2195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16895216#comment-16895216
]
Dale Richardson edited comment on METRON-2195 at 7/29/19 12:49 PM:
-------------------------------------------------------------------
[~otto] you are technique correct. Java does not natively support lazy
evaluation. You can fudge the line a little bit and update the API to accept a
lambda function which wraps your expensive operation. The lambda gets executed
only if the logging level says it's required. Otherwise the cost of evaluation
of the lambda body is not incurred.
But to get this you explicitly have to update your API to take a lambda, and
you have to explicitly check the logging level and explicitly execute the
lambda only when the result is required. So definitely not "native support",
but the end result is the same.
was (Author: tigerquoll):
[~otto] you are technique correct. Java does not natively support lazy
evaluation. You can fudge the line a little bit and update the API to accept
a lambda function, which wraps your expensive operation. The lambda gets
executed only if the logging level says it's required. Otherwise the cost of
evaluation the lambda body is not incurred.
> Add defensive log level checks when constructing logs is expensive
> ------------------------------------------------------------------
>
> Key: METRON-2195
> URL: https://issues.apache.org/jira/browse/METRON-2195
> Project: Metron
> Issue Type: Improvement
> Reporter: Otto Fowler
> Priority: Critical
> Time Spent: 10m
> Remaining Estimate: 0h
>
> There are instances where we log, and output strings for json objects and
> other things that are quite expensive.
> These are done regardless of the log level being enabled and can increase
> performance significantly:
> https://gist.github.com/mmiklavc/7fd6af13bfa0ca05d9b3f4e7806c8d77
> https://github.com/apache/metron/blob/master/metron-platform/metron-writer/metron-writer-storm/src/main/java/org/apache/metron/writer/hdfs/HdfsWriter.java#L127
> We need to find places where this happens, and employ the best practice check
> for the log level being enabled ( best practice if your parameters or log
> message construction takes a lot of time ).
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)