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

Fix for finagle-chirper locking problem #168

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Changes from 1 commit
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
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 @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, there is a race condition in accessing the cache, but that's probably not very important for the benchmark overall.

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