-
Notifications
You must be signed in to change notification settings - Fork 325
Instrument Runnables/Callables instead of wrapping them #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
felixbarny
merged 15 commits into
elastic:master
from
felixbarny:executor-instrument-runnables
Jun 17, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
140d51c
Instrument Runnables/Callables instead of wrapping
felixbarny c6095a7
Add changelog
felixbarny 2424cdc
Instrument ExecutorService#invoke{All|Any}
felixbarny 28fa795
Fix for Executors that execute on current thread
felixbarny aa9610e
Instrument ForkJoinPool and ScheduledExecutorService
felixbarny d701890
Speed up tests by avoiding to call Mockito spy in hot method
felixbarny 332e1fb
Fix Javadoc error
felixbarny a8f5b7e
Remove unused CallDepth
felixbarny 08ecfb8
Merge remote-tracking branch 'origin/master' into executor-instrument…
felixbarny b9b5d7d
Add global expunging of stale WeakConcurrentMap entries
felixbarny 6463427
Revert problematic usages of WeakMapSupplier
felixbarny a51ad0e
Add executor-collection instrumentation group
felixbarny 38493d9
Update docs
felixbarny 4a4e002
Disable problematic async Dubbo tests for now
felixbarny 48f75e1
Merge branch 'master' into executor-instrument-runnables
felixbarny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2020 Elastic and contributors | ||
| * %% | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.collections; | ||
|
|
||
| import co.elastic.apm.agent.context.AbstractLifecycleListener; | ||
| import co.elastic.apm.agent.impl.ElasticApmTracer; | ||
| import co.elastic.apm.agent.util.ExecutorUtils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Regularly calls {@link WeakMapSupplier#expungeStaleEntries()} | ||
| */ | ||
| public class WeakMapCleaner extends AbstractLifecycleListener implements Runnable { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(WeakMapCleaner.class); | ||
|
|
||
| private final ScheduledThreadPoolExecutor scheduler; | ||
|
|
||
| public WeakMapCleaner() { | ||
| this.scheduler = ExecutorUtils.createSingleThreadSchedulingDeamonPool("weak-map-cleaner"); | ||
| } | ||
|
|
||
| @Override | ||
| public void start(ElasticApmTracer tracer) { | ||
| scheduler.scheduleWithFixedDelay(this, 1, 1, TimeUnit.SECONDS); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() throws Exception { | ||
| scheduler.shutdownNow(); | ||
| scheduler.awaitTermination(1, TimeUnit.SECONDS); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| try { | ||
| WeakMapSupplier.expungeStaleEntries(); | ||
| } catch (Exception e) { | ||
| logger.error(e.getMessage(), e); | ||
| } | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapSupplier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2020 Elastic and contributors | ||
| * %% | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.collections; | ||
|
|
||
| import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap; | ||
| import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentSet; | ||
|
|
||
| /** | ||
| * The canonical place to get a new instance of a {@link WeakConcurrentMap}. | ||
| * Do not instantiate a {@link WeakConcurrentMap} directly to benefit from the global cleanup of stale entries. | ||
| */ | ||
| public class WeakMapSupplier { | ||
| private static final WeakConcurrentSet<WeakConcurrentMap<?, ?>> registeredMaps = new WeakConcurrentSet<>(WeakConcurrentSet.Cleaner.INLINE); | ||
|
|
||
| public static <K, V> WeakConcurrentMap<K, V> createMap() { | ||
| WeakConcurrentMap<K, V> result = new WeakConcurrentMap<>(false); | ||
| registeredMaps.add(result); | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Calls {@link WeakConcurrentMap#expungeStaleEntries()} on all registered maps, | ||
| * causing the entries of already collected keys to be removed. | ||
| * Avoids that the maps take unnecessary space for the {@link java.util.Map.Entry}, the {@link java.lang.ref.WeakReference} and the value. | ||
| * Failing to call this does not mean the keys cannot be collected. | ||
| */ | ||
| static void expungeStaleEntries() { | ||
| for (WeakConcurrentMap<?, ?> weakMap : registeredMaps) { | ||
| weakMap.expungeStaleEntries(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.