Skip to content

Commit

Permalink
Merge pull request #168 from renaissance-benchmarks/finagle-chirper-l…
Browse files Browse the repository at this point in the history
…ock-fix

Fix for finagle-chirper locking problem
  • Loading branch information
farquet authored Jul 1, 2019
2 parents 9b7649e + 1ccbdb6 commit e643e39
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,13 +225,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()
}
Expand Down

0 comments on commit e643e39

Please sign in to comment.