Forum: NGINX Fwd: Lua shared storage inconsistent?

Posted by Dan R (Guest)
on 2013-03-14 01:40
(Received via mailing list)
Hello,

I'm trying to count with a Lua-script the concurrent requests to a given
virtual host on the backend to which Nginx relays als reverse proxy.

My current code is somewhat more complex, but I try to reduce it to the
problematic one. Assuming we have a shared storage with sufficient 
memory
storage (let's say 100MB) I try the following:

** phase_access:
ngx.shared.counter:add(ngx.var.host,0) --makes sure the value exists
ngx.shared.counter:incr(ngx.var.host,1)


** phase_log
ngx.shared.counter:incr(ngx.var.host,-1)



I assumed -since the storage is supposedly atomic and shared- that this
will work. However when running a benchmark with eg 500 concurrent
connections, I will always be somewhat around 70 units in the minus at 
the
end of the benchmark. How come?

I tried setting the incrementer in other phases such as rewrite and the
decrementer in the body-phase, but that didn't change anything.
Also I noticed that taking a copy of the shared storage will not have 
that
copy update during sleep-loops of the given request and I have to fetch 
a
new one (with the penalty of keeping allocating new RAM)

Is there anything fundamentally wrong with my understanding of Nginx, is
there a bug in the lua implementation or what happened?

Thank you for helping me out - I certainly couldn't so far...
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.