0

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

一个简单的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) )
}
4

1 回答 1

0

您应该使用 Finagle 实现类似的性能,但我认为您粘贴的代码没有任何问题。你也许应该看看这个finagle memcached benchmark并根据你的使用情况调整它。

于 2014-03-06T17:40:38.677 回答