0
我在finagle應用程序中使用memcached編解碼器。但性能非常差,比使用spymemcached客戶端更糟糕。我用spinamemached獲得了8k req/s,用finagle的memcached編解碼器獲得了10 req/s。 memcached也在我的機器上運行。我錯過了什麼嗎? 應力試驗過程中發生錯誤的例子:Finagle + Memcached編解碼器性能不佳
Mar 05, 2014 10:22:10 AM com.twitter.finagle.builder.SourceTrackingMonitor handle
SEVERE: A server service httpserver threw an exception
com.twitter.finagle.ChannelWriteException: org.jboss.netty.channel.ConnectTimeoutException: connection timed out: localhost/127.0.0.1:11211
at com.twitter.finagle.NoStacktrace(Unknown Source)
Caused by: org.jboss.netty.channel.ConnectTimeoutException: connection timed out: localhost/127.0.0.1:11211
at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:137)
at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:83)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
如何在客戶端被配置成:
def client = Client(ClientBuilder()
.hosts(parseHosts())
.hostConnectionLimit(10)
.codec(Memcached())
.retries(2)
.daemon(true)
.build())
簡單的GET操作:
def getUserTries(username: String): Future[Int] = {
client.get(s"${username}_tries") flatMap { v => v match {
case Some(c:ChannelBuffer) => Future.value(UserCache.fromChannelBuffer(c).toInt)
case _ => Future.value(0)
}
}
和一組操作:
def saveUserTries(username: String, tries: Int): Future[Unit] = {
client.set(s"${username}_tries", UserCache.toChannelBuffer(tries.toString))
}