Skip to content
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

Replace Agrona with JCTools as it's Java 7 compatible #101

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apm-agent-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<artifactId>byte-buddy-agent</artifactId>
<version>${version.byte-buddy}</version>
</dependency>
<dependency>
<groupId>org.agrona</groupId>
<artifactId>agrona</artifactId>
<version>0.9.18</version>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import co.elastic.apm.objectpool.impl.QueueBasedObjectPool;
import co.elastic.apm.objectpool.impl.ThreadLocalObjectPool;
import org.agrona.concurrent.ManyToManyConcurrentArrayQueue;
import org.jctools.queues.MpmcArrayQueue;
import org.jctools.queues.atomic.MpmcAtomicArrayQueue;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
Expand All @@ -45,6 +47,8 @@ public class ObjectPoolBenchmark extends AbstractBenchmark {
private QueueBasedObjectPool<Transaction> agronaQueueObjectPool;
private MixedObjectPool<Transaction> mixedObjectPool;
private ThreadLocalObjectPool<Transaction> threadLocalObjectPool;
private QueueBasedObjectPool<Transaction> jctoolsQueueObjectPool;
private QueueBasedObjectPool<Transaction> jctoolsAtomicQueueObjectPool;

public static void main(String[] args) throws RunnerException {
run(ObjectPoolBenchmark.class);
Expand All @@ -53,6 +57,8 @@ public static void main(String[] args) throws RunnerException {
@Setup
public void setUp() {
blockingQueueObjectPool = new QueueBasedObjectPool<>(new ArrayBlockingQueue<>(256), true, Transaction::new);
jctoolsQueueObjectPool = new QueueBasedObjectPool<>(new MpmcArrayQueue<>(256), true, Transaction::new);
jctoolsAtomicQueueObjectPool = new QueueBasedObjectPool<>(new MpmcAtomicArrayQueue<>(256), true, Transaction::new);
agronaQueueObjectPool = new QueueBasedObjectPool<>(new ManyToManyConcurrentArrayQueue<>(256), true, Transaction::new);
mixedObjectPool = new MixedObjectPool<>(Transaction::new,
new ThreadLocalObjectPool<>(256, true, Transaction::new),
Expand All @@ -66,21 +72,37 @@ public void tearDown() {
System.out.println("Objects created by MixedObjectPool: " + mixedObjectPool.getGarbageCreated());
}

@Benchmark
// @Benchmark
@Threads(8)
public Transaction testNewOperator() {
return new Transaction();
}

@Benchmark
@Threads(8)
public Transaction testJctoolsAtomicQueueObjectPool() {
Transaction transaction = jctoolsAtomicQueueObjectPool.createInstance();
jctoolsAtomicQueueObjectPool.recycle(transaction);
return transaction;
}

// @Benchmark
@Threads(8)
public Transaction testArgonaQueueObjectPool() {
Transaction transaction = agronaQueueObjectPool.createInstance();
agronaQueueObjectPool.recycle(transaction);
return transaction;
}

// @Benchmark
@Benchmark
@Threads(8)
public Transaction testJctoolsQueueObjectPool() {
Transaction transaction = jctoolsQueueObjectPool.createInstance();
jctoolsQueueObjectPool.recycle(transaction);
return transaction;
}

//@Benchmark
@Threads(8)
public Transaction testBlockingQueueObjectPool() {
Transaction transaction = blockingQueueObjectPool.createInstance();
Expand All @@ -96,7 +118,7 @@ public Transaction testMixedObjectPool() {
return transaction;
}

@Benchmark
// @Benchmark
@Threads(8)
public Transaction testThreadLocalObjectPool() {
Transaction transaction = threadLocalObjectPool.createInstance();
Expand Down
6 changes: 3 additions & 3 deletions apm-agent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.agrona</groupId>
<artifactId>agrona</artifactId>
<version>0.9.18</version>
<groupId>org.jctools</groupId>
<artifactId>jctools-core</artifactId>
<version>2.1.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import co.elastic.apm.objectpool.impl.QueueBasedObjectPool;
import co.elastic.apm.report.Reporter;
import co.elastic.apm.report.ReporterConfiguration;
import org.agrona.concurrent.ManyToManyConcurrentArrayQueue;
import org.jctools.queues.atomic.AtomicQueueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stagemonitor.configuration.ConfigurationOption;
Expand All @@ -46,6 +46,8 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.jctools.queues.spec.ConcurrentQueueSpec.createBoundedMpmc;

/**
* This is the tracer implementation which provides access to lower level agent functionality.
* <p>
Expand Down Expand Up @@ -77,21 +79,21 @@ public class ElasticApmTracer {
this.stacktraceConfiguration = configurationRegistry.getConfig(StacktraceConfiguration.class);
this.lifecycleListeners = lifecycleListeners;
int maxPooledElements = configurationRegistry.getConfig(ReporterConfiguration.class).getMaxQueueSize() * 2;
transactionPool = new QueueBasedObjectPool<>(new ManyToManyConcurrentArrayQueue<Transaction>(maxPooledElements), false,
transactionPool = new QueueBasedObjectPool<>(AtomicQueueFactory.<Transaction>newQueue(createBoundedMpmc(maxPooledElements)),false,
new RecyclableObjectFactory<Transaction>() {
@Override
public Transaction createInstance() {
return new Transaction();
}
});
spanPool = new QueueBasedObjectPool(new ManyToManyConcurrentArrayQueue<Span>(maxPooledElements), false,
spanPool = new QueueBasedObjectPool<>(AtomicQueueFactory.<Span>newQueue(createBoundedMpmc(maxPooledElements)), false,
new RecyclableObjectFactory<Span>() {
@Override
public Span createInstance() {
return new Span();
}
});
errorPool = new QueueBasedObjectPool<>(new ManyToManyConcurrentArrayQueue<ErrorCapture>(maxPooledElements), false,
errorPool = new QueueBasedObjectPool<>(AtomicQueueFactory.<ErrorCapture>newQueue(createBoundedMpmc(maxPooledElements)), false,
new RecyclableObjectFactory<ErrorCapture>() {
@Override
public ErrorCapture createInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package co.elastic.apm.objectpool;

import co.elastic.apm.objectpool.impl.QueueBasedObjectPool;
import org.agrona.concurrent.ManyToManyConcurrentArrayQueue;
import org.jctools.queues.atomic.MpmcAtomicArrayQueue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -35,7 +35,7 @@ public class ObjectPoolTest {
@BeforeEach
void setUp() {
// objectPool = new ThreadLocalObjectPool<>(10, false, TestRecyclable::new);
objectPool = new QueueBasedObjectPool<>(new ManyToManyConcurrentArrayQueue<>(MAX_SIZE), true, TestRecyclable::new);
objectPool = new QueueBasedObjectPool<>(new MpmcAtomicArrayQueue<>(MAX_SIZE), true, TestRecyclable::new);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions elastic-apm-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<shadedPattern>co.elastic.apm.shaded.stagemonitor</shadedPattern>
</relocation>
<relocation>
<pattern>org.agrona</pattern>
<shadedPattern>co.elastic.apm.shaded.agrona</shadedPattern>
<pattern>org.jctools</pattern>
<shadedPattern>co.elastic.apm.shaded.jctools</shadedPattern>
</relocation>
</relocations>
<transformers>
Expand Down