You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2018/11/06 12:54:41 UTC
[1/2] qpid-proton-j git commit: PROTON-1916: Makes
StringsBenchmark::encodeStringMessage GC free. This closes #15.
Repository: qpid-proton-j
Updated Branches:
refs/heads/master d2c42ed5d -> 83609c475
PROTON-1916: Makes StringsBenchmark::encodeStringMessage GC free. This closes #15.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/65172034
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/65172034
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/65172034
Branch: refs/heads/master
Commit: 65172034332dfdf971a198a9c711cc1a9f39cdeb
Parents: d2c42ed
Author: Francesco Nigro <ni...@gmail.com>
Authored: Tue Aug 21 18:21:59 2018 +0200
Committer: Robbie Gemmell <ro...@apache.org>
Committed: Tue Nov 6 12:46:39 2018 +0000
----------------------------------------------------------------------
.../apache/qpid/proton/message/StringsBenchmark.java | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/65172034/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
----------------------------------------------------------------------
diff --git a/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java b/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
index 77f70a8..d0d7284 100644
--- a/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
+++ b/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
@@ -18,6 +18,8 @@
package org.apache.qpid.proton.message;
import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+import org.apache.qpid.proton.codec.WritableBuffer;
+import org.apache.qpid.proton.codec.WritableBuffer.ByteBufferWrapper;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
@@ -39,7 +41,7 @@ public class StringsBenchmark extends MessageBenchmark
private String string3;
private Message message;
- private byte[] buffer = new byte[8096];
+ private WritableBuffer buffer;
@Setup
public void init(Blackhole blackhole)
@@ -48,6 +50,7 @@ public class StringsBenchmark extends MessageBenchmark
super.init();
initStrings();
initStringMessage();
+ initWritableBuffer();
encode();
}
@@ -67,6 +70,11 @@ public class StringsBenchmark extends MessageBenchmark
message.setBody(new AmqpValue(PAYLOAD));
}
+ private void initWritableBuffer()
+ {
+ buffer = ByteBufferWrapper.allocate(8096);
+ }
+
@Benchmark
@Override
public ByteBuffer encode()
@@ -90,9 +98,10 @@ public class StringsBenchmark extends MessageBenchmark
}
@Benchmark
- public byte[] encodeStringMessage()
+ public WritableBuffer encodeStringMessage()
{
- message.encode(buffer, 0, buffer.length);
+ buffer.position(0);
+ message.encode(buffer);
return buffer;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-proton-j git commit: PROTON-1958: use a per-Timer counter
value such that its Tasks naturally order if their deadlines are equal
Posted by ro...@apache.org.
PROTON-1958: use a per-Timer counter value such that its Tasks naturally order if their deadlines are equal
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/83609c47
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/83609c47
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/83609c47
Branch: refs/heads/master
Commit: 83609c4752fbdaa1ddfa032285e5caa09b61f480
Parents: 6517203
Author: Robbie Gemmell <ro...@apache.org>
Authored: Tue Nov 6 12:53:19 2018 +0000
Committer: Robbie Gemmell <ro...@apache.org>
Committed: Tue Nov 6 12:53:19 2018 +0000
----------------------------------------------------------------------
.../qpid/proton/reactor/impl/TaskImpl.java | 7 +--
.../apache/qpid/proton/reactor/impl/Timer.java | 4 +-
.../apache/qpid/proton/reactor/ReactorTest.java | 31 ++++++++++++
.../qpid/proton/reactor/impl/TaskImplTest.java | 53 ++++++++++++++++++++
4 files changed, 89 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/83609c47/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/TaskImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/TaskImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/TaskImpl.java
index 11bb6b8..d360ee7 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/TaskImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/TaskImpl.java
@@ -21,8 +21,6 @@
package org.apache.qpid.proton.reactor.impl;
-import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.qpid.proton.engine.Record;
import org.apache.qpid.proton.engine.impl.RecordImpl;
import org.apache.qpid.proton.reactor.Reactor;
@@ -32,13 +30,12 @@ public class TaskImpl implements Task, Comparable<TaskImpl> {
private final long deadline;
private final int counter;
private boolean cancelled = false;
- private final AtomicInteger count = new AtomicInteger();
private Record attachments = new RecordImpl();
private Reactor reactor;
- public TaskImpl(long deadline) {
+ public TaskImpl(long deadline, int counter) {
this.deadline = deadline;
- this.counter = count.getAndIncrement();
+ this.counter = counter;
}
@Override
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/83609c47/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/Timer.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/Timer.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/Timer.java
index b8df19d..0351196 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/Timer.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/Timer.java
@@ -22,6 +22,7 @@
package org.apache.qpid.proton.reactor.impl;
import java.util.PriorityQueue;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.qpid.proton.engine.Collector;
import org.apache.qpid.proton.engine.Event.Type;
@@ -32,13 +33,14 @@ public class Timer {
private CollectorImpl collector;
private PriorityQueue<TaskImpl> tasks = new PriorityQueue<TaskImpl>();
+ private AtomicInteger counter = new AtomicInteger();
public Timer(Collector collector) {
this.collector = (CollectorImpl)collector;
}
Task schedule(long deadline) {
- TaskImpl task = new TaskImpl(deadline);
+ TaskImpl task = new TaskImpl(deadline, counter.incrementAndGet());
tasks.add(task);
return task;
}
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/83609c47/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java b/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java
index 387446e..fde9219 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/reactor/ReactorTest.java
@@ -33,6 +33,7 @@ import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import junit.framework.AssertionFailedError;
@@ -487,6 +488,36 @@ public class ReactorTest {
taskHandler.assertEvents(Type.TIMER_TASK);
}
+ @Test
+ public void scheduleWithEqualDeadline() throws IOException {
+ final int count = 10;
+ final ArrayList<Integer> taskRunOrder = new ArrayList<Integer>();
+
+ class TaskHandler extends BaseHandler {
+ private int _counter;
+
+ private TaskHandler(int counter) {
+ _counter = counter;
+ }
+
+ @Override
+ public void onTimerTask(Event event) {
+ taskRunOrder.add(_counter);
+ }
+ }
+
+ final List<Integer> expectedOrder = new ArrayList<>();
+ for(int i = 0 ; i < count; i++) {
+ reactor.schedule(0, new TaskHandler(i));
+ expectedOrder.add(i);
+ }
+
+ reactor.run();
+ reactor.free();
+
+ assertEquals(expectedOrder, taskRunOrder);
+ }
+
private class BarfException extends RuntimeException {
private static final long serialVersionUID = -5891140258375562884L;
}
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/83609c47/proton-j/src/test/java/org/apache/qpid/proton/reactor/impl/TaskImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/reactor/impl/TaskImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/reactor/impl/TaskImplTest.java
new file mode 100644
index 0000000..23159d9
--- /dev/null
+++ b/proton-j/src/test/java/org/apache/qpid/proton/reactor/impl/TaskImplTest.java
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.
+ *
+ */
+package org.apache.qpid.proton.reactor.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TaskImplTest {
+
+ @Test
+ public void testCompareToWithSameObject() {
+ TaskImpl task = new TaskImpl(1000, 1);
+ Assert.assertEquals(0, task.compareTo(task));
+ }
+
+ @Test
+ public void testCompareToWithDifferentDeadlines() {
+ TaskImpl task1 = new TaskImpl(1000, 1);
+ TaskImpl task2 = new TaskImpl(2000, 2);
+
+ Assert.assertTrue(task1.compareTo(task2) < 0);
+ Assert.assertTrue(task2.compareTo(task1) > 0);
+ }
+
+ @Test
+ public void testCompareToWithSameDeadlines() {
+ int deadline = 1000;
+ TaskImpl task1 = new TaskImpl(deadline, 1);
+ TaskImpl task2 = new TaskImpl(deadline, 2);
+
+ Assert.assertTrue("Expected task1 to order 'less' due to being created first", task1.compareTo(task2) < 0);
+ Assert.assertTrue("Expected task2 to order 'greater' due to being created second", task1.compareTo(task2) < 0);
+ Assert.assertTrue(task2.compareTo(task1) > 0);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org