Skip to content

Commit

Permalink
[aggregator] fix thread leak + dont always start scheduler (#129)
Browse files Browse the repository at this point in the history
* [aggregator] fix thread leak + dont always start scheduler

* [aggregator] remove commented lines

* [circleci] tie cache to java version
  • Loading branch information
truthbk committed Dec 2, 2020
1 parent 73818a8 commit bd4bbbb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
19 changes: 16 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
version: 2.1

commands:
create_custom_cache_lock:
description: "Create custom cache lock for java version."
parameters:
filename:
type: string
steps:
- run:
name: Grab java version and dump to file
command: java -version > << parameters.filename >>

default_steps: &default_steps
steps:
- checkout
- create_custom_cache_lock:
filename: java-version-lock.txt

# Download and cache dependencies
- restore_cache:
keys:
- -v5-dependencies-{{ checksum "pom.xml" }}-{{ arch }}
- -v6-dependencies-{{ checksum "pom.xml" }}-{{ checksum "java-version-lock.txt" }}-{{ arch }}
# fallback to using the latest cache if no exact match is found
- -v5-dependencies-
- -v6-dependencies-

- run: mvn dependency:go-offline

- save_cache:
paths:
- ~/.m2
key: -v5-dependencies-{{ checksum "pom.xml" }}-{{ arch }}
key: -v6-dependencies-{{ checksum "pom.xml" }}-{{ checksum "java-version-lock.txt" }}-{{ arch }}
- run: |
mvn clean install -Dgpg.skip $MVN_EXTRA_OPTS
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/timgroup/statsd/StatsDAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public class StatsDAggregator {
Arrays.asList(Message.Type.COUNT, Message.Type.GAUGE, Message.Type.SET));
protected final ArrayList<Map<Message, Message>> aggregateMetrics;

// protected final Map<Message, Message> aggregateMetrics = new HashMap<>();
protected final Timer scheduler = new Timer(AGGREGATOR_THREAD_NAME, true);

protected final int shardGranularity;
protected final long flushInterval;

private final StatsDProcessor processor;

protected Timer scheduler = null;

private Telemetry telemetry;

private class FlushTask extends TimerTask {
Expand All @@ -54,6 +53,10 @@ public StatsDAggregator(final StatsDProcessor processor, final int shards, final
this.shardGranularity = shards;
this.aggregateMetrics = new ArrayList<>(shards);

if (flushInterval > 0) {
this.scheduler = new Timer(AGGREGATOR_THREAD_NAME, true);
}

for (int i = 0 ; i < this.shardGranularity ; i++) {
this.aggregateMetrics.add(i, new HashMap<Message, Message>());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/timgroup/statsd/StatsDProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ boolean isShutdown() {

void shutdown() {
shutdown = true;
aggregator.stop();
executor.shutdown();
}
}

0 comments on commit bd4bbbb

Please sign in to comment.