Re: contributor permission for Beam Jira tickets

2020-02-10 Thread Yixing Zhang
Thank you, Kenneth!

On Mon, Feb 10, 2020 at 7:24 PM Kenneth Knowles  wrote:

> Welcome! I have added you to the Contributors role so you can be assigned
> Jira tickets.
>
> On Mon, Feb 10, 2020 at 4:28 PM Yixing Zhang 
> wrote:
>
>> Hi,
>>
>> This is Yixing from LinkedIn. I'm closely working with Xinyu on Samza
>> runner. Can someone add me as a contributor for Beam's Jira issue tracker?
>> I would like to create/assign tickets for my work.
>>
>> jira username: YixingZhang
>>
>> Thanks,
>> Yixing Zhang
>>
>


contributor permission for Beam Jira tickets

2020-02-10 Thread Yixing Zhang
Hi,

This is Yixing from LinkedIn. I'm closely working with Xinyu on Samza
runner. Can someone add me as a contributor for Beam's Jira issue tracker?
I would like to create/assign tickets for my work.

jira username: YixingZhang

Thanks,
Yixing Zhang


Re: Updating Metrics Counter in user defined thread

2020-01-21 Thread Yixing Zhang
Thanks for the suggestions, Robert and Alex! Although the suggested
solutions may work, all of them require users to change their code,
which is not ideal. Creating new threads and updating metrics in callback
functions are pretty common for samza-runner users. We'd like to come up
with a way that we can make some changes in the runner side to enable this
use case.

We'd like to propose a short-term solution for this use case. Here are the
steps:
1. In MetricsEnvironment
<https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricsEnvironment.java>
class,
add a static method "public static void setGlobalContainer(@Nullable
MetricsContainer container)" that can be called by runners to set a global
metrics container per JVM.
2. In MetricsEnvironment class, modify the getCurrentContainer() method to
return global container when the thread-local container is null and the
global container is not null.
3. For each runner, developers can add
MetricsEnvironment.setGloabalContainer() to the runner code to enable this
feature. There will be no side effect
if MetricsEnvironment.setGloabalContainer() is not called.

In this way, it allows beam runners to decide whether to support updating
metrics in user thread or not. If it's not supported, nothing will be
changed. If it's supported, users don't need to change their application
code to enable it. One drawback of this short-term solution is that the
step name is missing for the global container. However, in this case, users
are updating the metrics in their threads, they may not care too much about
the step names. They can find the metrics with just metric names.

Please give me some feedbacks on this proposal and let's discuss whether to
implement this.

Thanks,
Yixing

On Fri, Jan 17, 2020 at 1:37 PM Alex Amato  wrote:

> The one work around I can suggest, is if its at all possible to
> parallelize the work by keying the data. This requires modifying the
> pipeline. I.e. the first ParDo produces elements for different keys. Then
> follow that with a GBK. Then the downstream pardo will have a thread for
> every key. IF those threads all compute something and you need to combine
> those results in a single place, you may need to produce elements which
> again rekey the data, follow that with another GBK and a combiner.
>
> Something sort of like this, if I understand correctly.
>
> ParDo
> GBK
> ParDo
> GBK
> Combiner
>
> But this work around may not work for all problems necessarily. And if the
> metrics are designed to be aggregated within a single UDF, ParDo or
> Combiner. So if you needed the counters to be aggregated across all of
> these operations as well, then this may not work.
>
> The backed in assumption of using the thread local setup is that
> parallelism is typically handled by the Beam, rather than introducing a
> separate threading model. Though, perhaps breaking out of this threading
> model is more common than we initially thought.
>
> I hope thats helpful, sorry we don't have an easy fix.
>
> On Fri, Jan 17, 2020 at 11:39 AM Robert Bradshaw 
> wrote:
>
>> Yes, this is an issue with how counters are implemented, and there's
>> no good workaround. (We could use inheritable thread locals in Java,
>> but that assumes the lifetime of the thread does not outlive the
>> lifetime of the DoFn, and would probably work poorly with
>> threadpools). In the meantime, one can update (say) a Map in the
>> spawned threads and let the main thread in processElement (and likely
>> finishBundle) increment the metrics in a threadsafe way based on the
>> contents of the map.
>>
>> On Fri, Jan 17, 2020 at 11:29 AM Yixing Zhang 
>> wrote:
>> >
>> > Hi Beam Committers,
>> >
>> > I am a developer on Beam Samza runner. Currently, we are seeing some
>> issues where our users failed to update Metrics in their thread. I am
>> wondering if anyone has suggestions on this issue.
>> >
>> > Problem:
>> > MetricsContainer is ThreadLocal in MetricsEnvironment. Whenever
>> DelegatingCounter.inc() is called. It tries to find the MetricsContainer in
>> the current thread and update the corresponding CounterCell. For Samza
>> runner, we have a FnWithMetricsWrapper to set the MetricsContainer for the
>> current thread before each DoFn is run. However, if users define their own
>> threads inside a Pardo function and try to update the Metrics in their
>> threads, they will fail to update the Metrics and get error log "Unable to
>> update metrics on the current thread".
>> >
>> > Example:
>> >
>> > pipeline
>> > .apply(Create.of(inputData))
>> > .apply(ParDo.of(new DoFn, Void&

Updating Metrics Counter in user defined thread

2020-01-17 Thread Yixing Zhang
Hi Beam Committers,

I am a developer on Beam Samza runner. Currently, we are seeing some issues
where our users failed to update Metrics in their thread. I am wondering if
anyone has suggestions on this issue.

Problem:
MetricsContainer

is
ThreadLocal in MetricsEnvironment
.
Whenever DelegatingCounter
.inc()
is called. It tries to find the MetricsContainer in the current thread and
update the corresponding CounterCell. For Samza runner, we have a
FnWithMetricsWrapper

to
set the MetricsContainer for the current thread before each DoFn is run.
However, if users define their own threads inside a Pardo function and try
to update the Metrics in their threads, they will fail to update the
Metrics and get error log "Unable to update metrics on the current
thread"

.

Example:

pipeline
.apply(Create.of(inputData))
.apply(ParDo.of(new DoFn, Void>() {
  @ProcessElement
  public void processElement(ProcessContext context) {
Metrics.counter("test", "counter1").inc();
Thread thread = new Thread(() -> {
  Metrics.counter("test", "counter2").inc();
}, "a user-defined thread");
thread.start();
  }
}));

In this case, counter1 can be updated but counter2 cannot be updated
because MetricsContainer has not been set in their thread.

We don't have any control of user-defined threads. So, it seems impossible
for our runner to set the MetricsContainer for their threads. Can someone
give me some suggestions either from developer's perspective or from user's
perspective about how to make this use case work?

Thanks,
Yixing