You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by gi...@git.apache.org on 2017/09/22 13:39:24 UTC
[GitHub] markusthoemmes opened a new pull request #2797: Use non-blocking computation of cache values.
markusthoemmes opened a new pull request #2797: Use non-blocking computation of cache values.
URL: https://github.com/apache/incubator-openwhisk/pull/2797
Currently, each time we try to get a value out of our cache `putIfAbsent` is called, which causes thread-contention. Instead, this uses `computeIfAbsent` which does a `get` first and thus is non-blocking for getting cached values under load.
## Testcode:
```scala
object Test {
import scala.concurrent.ExecutionContext.Implicits.global
implicit val as = ActorSystem()
def main(args: Array[String]): Unit = {
val cache: ConcurrentMapBackedCache[String] = new ConcurrentMapBackedCache(
Caffeine
.newBuilder()
.asInstanceOf[Caffeine[Any, Future[String]]]
.expireAfterWrite(5, TimeUnit.MINUTES)
.softValues()
.build()
.asMap())
(1 to 100000000).par.foreach { _ =>
cache.apply("testKey", () => akka.pattern.after(3.seconds, as.scheduler)(Future.successful("test2")))
}
as.terminate()
}
}
```
## With our current code:
![image](https://user-images.githubusercontent.com/1289147/30746992-12c4fd96-9fac-11e7-9f6d-1c238307df68.png)
![image](https://user-images.githubusercontent.com/1289147/30746995-16d39d7a-9fac-11e7-9d97-8e8fef738ac1.png)
## With the updated code:
![image](https://user-images.githubusercontent.com/1289147/30747000-1b6d21ee-9fac-11e7-8f77-3c9f10c83ad5.png)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services