ngx.shared.DICT atomic questions

282 views
Skip to first unread message

Guy Cheung

unread,
Sep 20, 2016, 3:35:51 AM9/20/16
to openresty-en
Hi All

I have used ngx.shared.DICT as the data cache on my business. Beacuse of high concurrency requests(2w qps) on 48 workers of nginx, I'm sensitived with shared DICT operations with atomic block.

I want to know when use ngx.shared.DICT.get/set, the atomic method block the specified key only, or the entire dict? for example:
Does the ngx.shared.DICT.set('a', 1) and ngx.shared.DICT.set('b', 2)  could be run same time?
Does the ngx.shared.DICT.set('a', 1) and ngx.shared.DICT.get('b', 2) could be run same time?

Thx!

Robert Paprocki

unread,
Sep 20, 2016, 1:08:10 PM9/20/16
to openre...@googlegroups.com
Hi,

Both read and write operators to a shared memory zone lock the zone for the duration of the operation. Because underlying rbtree access is very fast, and locking doesn't require a syscall or yielding the thread, this is a very fast operation. Because of this, two accesses (either read or write) running at _near_ simultaneous instance would not fight, one would occur first, lock the zone, perform its operation (either read or write), then unlock the zone, allowing the next request to the dictionary to be served. Since the zone is globally shared across all workers, this lock influences all workers, so multiple workers attempting to access the zone will be served in serial, without any conflict or race condition. And again, because the zone lock is very efficient and doesn't require any syscalls or I/O, this lock is held for only a very short time (the exception is when something like get_keys() is called on a zone with very many keys, then the zone has to be locked while the whole thing is traversed).

See also https://groups.google.com/forum/#!topic/openresty-en/LmXygRJkN5g for a similar discussion on shared memory zone locking.

 

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guy Cheung

unread,
Sep 21, 2016, 10:07:18 PM9/21/16
to openresty-en, rob...@cryptobells.com
Hi rpaprocki, 
Thanks for your answer!
Hi,

To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages