Fwd: Lua shared storage inconsistent?

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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs