5

I'm building a REQ/REP service with zeromq and the REP part is in Scala and using Akka actors.

Here is the actor

class ReplyActor extends Actor {

  println("Listening..")

  def receive = {
    case m: ZMQMessage =>
      sender ! ZMQMessage(Seq(Frame("world")))
    case _ =>
      sender ! ZMQMessage(Seq(Frame("didn't understand?")))
  }

}

And my main function

object Replyer extends App {
  val system = ActorSystem("zmq")
  val serverSocket = ZeroMQExtension(system).newRepSocket(
    Array(
      Bind("tcp://127.0.0.1:1234"),
      Listener(system.actorOf(Props[ReplyActor]))
    )
  )
}

My REQ code is in python

import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:1234")

startTime = time.time() 
for i in range(10):
    msg = "msg %s" % i
    socket.send("hello")
    msg_in = socket.recv()

print 'That took ', time.time()-startTime, 'seconds'

It takes about 1 second for 10 messages, so my question is why is it so slow? If I build the REP in python it is really fast so I'm accusing Akka zeromq binding.

Extra info: I'm using Scala 2.9.2 and the newest Akka 2.0.3 (but also tried with 2.0.2)

j0k
  • 22,600
  • 28
  • 79
  • 90
user918712
  • 113
  • 1
  • 8
  • 1 second for 10 messages sounds like 100ms delay between each, my guess: http://doc.akka.io/docs/akka/2.0.3/general/configuration.html#akka-zeromq – Viktor Klang Aug 23 '12 at 18:50
  • @ViktorKlang Thanks :) Actually I had already tried that but FSC hadn't noticed the change in the application.conf, but when I rebuild it with SBT it worked. Setting poll-timeout to 1ms gives me 500 msg pr second. Is this as expected? If you make an answer I'll accept it. – user918712 Aug 23 '12 at 19:21
  • Could be due to the scheduler config, you might have to tweak that as well. Cheers, √ – Viktor Klang Aug 25 '12 at 19:44
  • I think we will look into re-implementing parts of the akka-zeromq code. Please see discussion on the [Akka user list](https://groups.google.com/d/topic/akka-user/lGBb8GTouV0/discussion) – user918712 Aug 28 '12 at 10:26
  • Fair enough, looking forward to the Pull Request(s). – Viktor Klang Aug 28 '12 at 11:02

0 Answers0