-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request akka#21372 from drewhk/wip-21203-cached-actorref-l…
…ookup-drewhk akka#21203: Cache/memoize ActorRef resolution
- Loading branch information
Showing
7 changed files
with
575 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
akka-bench-jmh/src/main/scala/akka/util/LruBoundedCacheBench.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.util | ||
|
||
import java.util | ||
import java.util.concurrent.TimeUnit | ||
|
||
import akka.remote.artery.LruBoundedCache | ||
import org.openjdk.jmh.annotations.{ Param, _ } | ||
|
||
import scala.util.Random | ||
|
||
@State(Scope.Benchmark) | ||
@Measurement(timeUnit = TimeUnit.MICROSECONDS) | ||
class LruBoundedCacheBench { | ||
|
||
var javaHashMap: java.util.HashMap[String, String] = _ | ||
|
||
@Param(Array("1024", "8192")) | ||
var count = 0 | ||
|
||
@Param(Array("128", "256")) | ||
var stringSize = 0 | ||
var lruCache: LruBoundedCache[String, String] = _ | ||
|
||
@Param(Array("90", "99")) | ||
var loadFactor: Int = _ | ||
|
||
var toAdd: String = _ | ||
var toRemove: String = _ | ||
var toGet: String = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
val loadF: Double = loadFactor / 100.0 | ||
val threshold = (loadF * count).toInt | ||
|
||
val random = Random | ||
javaHashMap = new util.HashMap[String, String](count) | ||
lruCache = new LruBoundedCache[String, String](count, threshold) { | ||
override protected def compute(k: String): String = k | ||
override protected def hash(k: String): Int = k.hashCode | ||
override protected def isCacheable(v: String): Boolean = true | ||
} | ||
|
||
// Loading | ||
for (i <- 1 to threshold) { | ||
val value = random.nextString(stringSize) | ||
if (i == 1) toGet = value | ||
toRemove = value | ||
javaHashMap.put(value, value) | ||
lruCache.get(value) | ||
} | ||
|
||
toAdd = random.nextString(stringSize) | ||
|
||
} | ||
|
||
@Benchmark | ||
def addOne_lruCache(): String = { | ||
lruCache.getOrCompute(toAdd) | ||
} | ||
|
||
@Benchmark | ||
def addOne_hashMap(): String = { | ||
javaHashMap.put(toAdd, toAdd) | ||
javaHashMap.get(toAdd) | ||
} | ||
|
||
@Benchmark | ||
def addOne_hashMap_remove_put_get(): String = { | ||
javaHashMap.remove(toRemove) | ||
javaHashMap.put(toAdd, toAdd) | ||
javaHashMap.get(toAdd) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.