From ab2e7cd1168406248af36b435eab124f75aee9ff Mon Sep 17 00:00:00 2001 From: Francois Farquet Date: Mon, 1 Jul 2019 11:17:37 +0200 Subject: [PATCH 1/2] Fix for finagle-chirper locking problem #164 --- .../renaissance/twitter/finagle/FinagleChirper.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala b/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala index a0172d70..d56eff5a 100644 --- a/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala +++ b/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala @@ -7,6 +7,7 @@ import java.nio.ByteBuffer import java.nio.charset.StandardCharsets import java.util.Comparator import java.util.concurrent.atomic.AtomicReference +import java.util.concurrent.atomic.AtomicInteger import com.google.common.collect.ConcurrentHashMultiset import com.google.common.collect.Multiset.Entry @@ -225,12 +226,11 @@ class FinagleChirper extends RenaissanceBenchmark { class Cache(val index: Int, val service: Service[Request, Response]) extends Service[Request, Response] { val lock = new AnyRef - val cache = new mutable.HashMap[String, Buf] - var count = 0 + val cache = new concurrent.TrieMap[String, Buf] + val count = new AtomicInteger - override def apply(req: Request): Future[Response] = lock.synchronized { - count += 1 - val uid = math.abs((index * count).toDouble.hashCode) + override def apply(req: Request): Future[Response] = { + val uid = math.abs((index * count.incrementAndGet()).toDouble.hashCode) if (uid % invalidationPeriodicity == 0) { cache.clear() } From 1ccbdb60a77ac98c2f022a77b1871f061fa76cfd Mon Sep 17 00:00:00 2001 From: Francois Farquet Date: Mon, 1 Jul 2019 21:19:59 +0200 Subject: [PATCH 2/2] Remove lock object --- .../scala/org/renaissance/twitter/finagle/FinagleChirper.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala b/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala index d56eff5a..f2a86618 100644 --- a/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala +++ b/benchmarks/twitter-finagle/src/main/scala/org/renaissance/twitter/finagle/FinagleChirper.scala @@ -225,7 +225,6 @@ class FinagleChirper extends RenaissanceBenchmark { class Cache(val index: Int, val service: Service[Request, Response]) extends Service[Request, Response] { - val lock = new AnyRef val cache = new concurrent.TrieMap[String, Buf] val count = new AtomicInteger