Skip to content

Instantly share code, notes, and snippets.

@tanmaykm
Created February 15, 2016 09:59
Show Gist options
  • Save tanmaykm/8352059108c6b34f5ecf to your computer and use it in GitHub Desktop.
Save tanmaykm/8352059108c6b34f5ecf to your computer and use it in GitHub Desktop.
zmq leak test
#const ENDPOINT = "tcp://localhost:9875"
const ENDPOINT = "ipc:///tmp/testZMQ";
const pid = getpid();
const MSG = "abcdefghijklmnopqrstuvwxyz";
vsz() = parse(Int, split(open(readstring,`ps -p $pid -o vsz`),"\n")[2]);
vsz(s) = println(s, vsz())
vsz("Initial VSZ=");
using ZMQ
vsz("After loading ZMQ, my VSZ=");
function doopenclose(ctx)
v1 = vsz()
for i in 1:10000
socket = Socket(ctx, PUB);
ZMQ.bind(socket, ENDPOINT);
ZMQ.close(socket);
end
v2 = vsz()
v2 - v1
end
function dopub(ctx)
v1 = vsz()
socket = Socket(ctx, PUB);
ZMQ.bind(socket, ENDPOINT);
M = Message(MSG)
for i = 1:1000000
ZMQ.send(socket, M)
end
ZMQ.close(socket);
v2 = vsz()
v2 - v1
end
function dosub(ctx)
v1 = vsz()
socket = Socket(ctx, SUB);
ZMQ.connect(socket, ENDPOINT);
for i = 1:1000000
ZMQ.recv(socket)
end
ZMQ.close(socket);
v2 = vsz()
v2 - v1
end
println("testing socket open and close")
v1 = vsz()
for i in 1:100
ctx = Context()
print(doopenclose(ctx), ", ");
ZMQ.close(ctx)
end
v2 = vsz()
println(". final:", v2-v1)
println("testing pub. vsz changes: ")
v1 = vsz()
for i in 1:100
ctx = Context()
print(dopub(ctx), ", ");
ZMQ.close(ctx)
end
v2 = vsz()
println(". final:", v2-v1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment