Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Add a cap to metrics communicator in TMasterSink and MetricsCacheSink #3355

Merged

Conversation

nwangtw
Copy link
Contributor

@nwangtw nwangtw commented Oct 3, 2019

Without the cap, when MetricsCacheSink is enabled but MetricsCache is not running, the communication will keep growing.

The same thing could happen with TMaster but it is less likely to have the problem.

while (!publishMetricsCommunicator.isEmpty()) {
TopologyMaster.PublishMetrics publishMetrics = publishMetricsCommunicator.poll();
TopologyMaster.PublishMetrics publishMetrics;
synchronized (publishMetricsCommunicator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that previously we didn't use synchronized during operations on publishMetricsCommunicator.
What have changed? Do we now work with publishMetricsCommunicator in different threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Before there were only 1 producer (metrics manager) and 1 consumer (sink client) for this communicator from two different threads.

In the change, the producer can remove entries from head too so it is competing with the consumer thread. A simpler way is to avoid adding new entries into the queue, then we don't need to synchronize the producer and the consumer. However, I feel that the recent data could be more important than the old data.

TopologyMaster.PublishMetrics publishMetrics;
synchronized (publishMetricsCommunicator) {
publishMetrics = publishMetricsCommunicator.poll();
}
Copy link
Member

Choose a reason for hiding this comment

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

hmm, if we change the while loop condition, maybe we could reduce the code duplicate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like while (synchronized (publishMetricsCommunicator) { publishMetrics = .... } ) {}?

As a non-java programmer, I don't know if it is ok. :D

But this is a valid point. Let me see if I can improve it.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@xiaoyao1991
Copy link
Member

👍

@nwangtw nwangtw merged commit 5a3dee5 into apache:master Oct 4, 2019
sreev pushed a commit to sreev/incubator-heron that referenced this pull request Apr 9, 2020
…apache#3355)

* Add a cap to metrics communicator in TMasterSink and MetricsCacheSink

* refactor while loop
nicknezis pushed a commit that referenced this pull request Sep 14, 2020
…#3355)

* Add a cap to metrics communicator in TMasterSink and MetricsCacheSink

* refactor while loop
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants