【问题标题】:Finagle + Memcached codec poor performanceFinagle + Memcached 编解码器性能不佳
【发布时间】:2014-03-05 13:33:12
【问题描述】:

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

【问题讨论】:

    标签: performance finagle


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 2020-10-22
      • 2014-03-28
      • 1970-01-01
      相关资源
      最近更新 更多