Hello!
On Wed, May 27, 2015 at 9:40 AM, kaspersky_us via openresty-en wrote:
> I am unsure how to integrate my C++ code in a way that would let me
> initialize it (which loads the data in memory) and then serve all requests
> across workers from nginx.
>
Will you update this data structure in your requests? If it's
read-only, then you can just load it in the context of "init_by_lua"
and let the operating system's "Copy-on-Write" (COW) feature save the
physical memory pages automatically for you across all the (forked)
nginx worker processes.
Otherwise you'll have to use nginx's shm facility to host your data
structure to ensure proper locking and data consistency. You can take
a look at ngx_lua's shared dict API for such an example.
> I saw information about developing C modules (but nothing about C++) or
> using FFI, but it's unclear to me how to use a shared C++ application (with
> data loaded once in memory)
>
Generally speaking, the best practice is to wrap your C++ operations
with a clean C interface and let FFI do the rest for you. C++ has
excellent C cooperation support anyway :) But it'll surely be more
complicated if you have to use shm to host your C++ data strucutres in
case that you need to modify them at request time.
Hope it helps :)
Best regards,
-agentzh