On Mon, Sep 5, 2016 at 4:36 AM, Dan <dane...@hotmail.com> wrote: > Hi, > > > I am trying to create a Julia server instance by using ZMQ with the > Req/Rep pattern. My Julia code for the Rep-server looks like this: > > module JServer > > # import zmq > using ZMQ > import Base.gc > > # create context > ctx=Context(); > # create socket > socket=Socket(ctx, REP); > # msg > msg = 0; > # repeatedly collect garbage every second > timer = Timer(gc, 1, 1); > > function connect(host, port) > > # connect > ZMQ.connect(socket, string("tcp://", host, ":", port)); > println(string("Julia server connected to ", host, " on port ", port)); > end > > > > function startServer() > # notify > println("Waiting for request...") > i = 1 > while i <= 2 > # invoke garbage collection > # gc(); > # Poll For message > msg = receive(); > println("Message received"); > # Reply > send(); > println("Message acknowledged"); > end > end > > > > function receive() > msg = ZMQ.recv(socket); > end > > > > function send() > ZMQ.send(socket, Message("test request")); > end > > > > function gc(event) > gc(); > end > > end > > I can successfully start the server by runnung this script (indicating > host and port via ARGS): > > # include server module > include(string(dirname(Base.source_path()), "\JServer.jl")); > # connect server > JServer.connect(ARGS[1], ARGS[2]); > # start server > JServer.startServer(); > > My tests seem to be odd, however: Whenever I send large messages from > client, i.e. ~1MB per message, Julia seems to properly keep tracking about > memory usage: The overall process memory remains constant. But when I am > sending small messaged (i.e. 10k per message) Julia memory usage is growing > permanenlty. In addition response time slows down over my requests. This > does not happen if I explicitly invoke the garbage collector inside the > while loop, but this would slow down the replies significantly. > > > I am using Julia 0.4.6. > > > Try 0.5.
> Is my code ok? Is there a callback solution in order to be able to avoid > the while loop? >