thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Armbrust <michael.armbr...@gmail.com>
Subject Re: Thrift / Scala concurrency issue
Date Thu, 17 Sep 2009 20:25:12 GMT
The JavaDoc for TNonBlockingServer says that "This allows for fairness
amongst all connected clients in terms of invocations. This server is
inherently single-threaded. If you want a limited thread pool coupled with
invocation-fairness, see THsHaServer."  So using TNonBlockingServer probably
isn't what you want.

In my application I do the following:
...
val processor = new StorageEngine.Processor(new StorageProcessor(env))
val transport = new TNonblockingServerSocket(port)
val protFactory = new TBinaryProtocol.Factory(true, true)
val serverOpt = new THsHaServer.Options
serverOpt.maxWorkerThreads=20
serverOpt.minWorkerThreads=2
val server = new THsHaServer(processor, transport, protFactory, serverOpt)
server.serve()
...

class StorageProcessor(env: Environment) extends StorageEngine.Iface {
...
    def get(ns: String, key: String): Record = {
        logger.debug("Starting get")
        Thread.sleep(10*1000) // Actual code here
        logger.debug("Ending get")
        new Record(key, null)
    }
...
}

It's definitely not serializing the requests as the logs look like this:
[DEBUG scads.storageprocessor] StorageService.scala:18(get) Starting get
[DEBUG scads.storageprocessor] StorageService.scala:18(get) Starting get
[DEBUG scads.storageprocessor] StorageService.scala:20(get) Ending get
[DEBUG scads.storageprocessor] StorageService.scala:20(get) Ending get

So, I'd try it again with THsHaServer and make sure there is nowhere else in
your code that could be serializing it.

Hope this helps!

Michael

On Wed, Sep 16, 2009 at 9:54 AM, Sebastian Latza <mail@sebastian-latza.de>wrote:

> Hi everybody,
>
> while Scala isn''t natively supported by Thrift, maybe someone has seen the
> same problem I'm facing.
> I have got a very simple Thrift service which is doing some processing (100
> to 1000ms) and then returns the result back to the client. When benchmarking
> I noticed that when adding more concurrent clients the performance degraded:
> while one client was getting 10 req/sec, two were getting 5 req/sec, and so
> on. So the server is handling the requests sequential for some reason. I
> have tried all implementations (TThreadPoolServer, TNonblockingServer,
> THsHaServer) with the same results. The implementation is quite vanilla:
>
> // Includes here...
>
> class ServiceHandler() extends service.Iface {
>        override def call_function(String: foo) : String = {
>                Thread.sleep(100)
>                return "result"
>        }
> }
>
> object server {
>  def main(args: Array[String]) {
>   val processor = new service.Processor(new ServiceHandler())
>   val socket = new TNonblockingServerSocket(9090)
>   val server = new TNonblockingServer(processor, socket)
>   server.serve()
> }
>
> Java 1.6.0_16, Scala 2.7.5, same results on Mac and Linux.
>
> Any hints what I might be running into here?
>
> Regards
> Sebastian
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message