Finagle + Memcached编解码器性能不佳

时间:2014-03-05 13:33:13

标签: performance finagle

我在finagle应用程序中使用memcached编解码器。但性能非常差,比使用spymemcached客户端更差。我使用finagle的memcached编解码器获得了8k req / s的spymemached和10 req / s。 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() )

简单的获取操作:

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) )
}

1 个答案:

答案 0 :(得分:0)

您应该与Finagle达到类似的性能,但我发现您粘贴的代码没有任何问题。 您应该查看此finagle memcached benchmark并根据您的使用情况进行调整。