[ 
https://issues.apache.org/jira/browse/FLINK-12681?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16851560#comment-16851560
 ] 

Biao Liu commented on FLINK-12681:
----------------------------------

The {{SimpleCounter}} is widely used. Especially in per-record path, it is 
extremely performance sensitive. So I would suggest implementing a new 
thread-safe {{Counter}} instead of {{SimpleCounter}}.
We can use it like this,
{{getRuntimeContext().getMetricGroup().counter("thread-safe counter", new 
ThreadSafeCounter()}}

BTW, it makes sense to me to provide a built-in thread-safe {{Counter}}, it's 
quite common. Will keep tracking this in other thread.

> Make SimpleCounter thread-safe.
> -------------------------------
>
>                 Key: FLINK-12681
>                 URL: https://issues.apache.org/jira/browse/FLINK-12681
>             Project: Flink
>          Issue Type: Improvement
>            Reporter: Piyush Goyal
>            Priority: Major
>
> While adding metrics to Elasticsearch connector, we noticed that the 
> SimpleCounter which seems like the main implementation of Counter interface 
> is not thread-safe. It makes it tricky/expensive to use it in a 
> multi-threaded context. 
> It should be a very simple change to make it thread-safe, and the performance 
> benefit (if any) of keeping it thread-unsafe doesn't seem worth the extra 
> care to use it in a multithreaded context. What do you think ?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to