perl module for nginx
lordnynex at gmail.com
Fri May 16 00:35:53 UTC 2014
I'm a bit pressed for time but want to throw out a few incomplete thoughts
You will have a very difficult time doing IPC between worker processes
unless you do IPC over a unix domain socket (and even then it sorta sucks).
IMHO this is sub-optimal as this module has the ability to block the entire
webserver on long running operations.
An example to frame this in would be preserving session state without a
third party process like redis or memcached. Since you have LUA built, you
may see better performance and footprint if you do the following:
- Create a shared dictionary at nginx init (example, perl-session-store).
This dictionary will be shared across all nginx worker processes in memory.
- Create an internal only LUA handler for setting/getting data out of the
- Implement some sort of locking mechanism in the above handler.
- Use something like $r->internal_redirect to get/set data in and out of
the above lua handler.
In this way you can preserve something like session data across all
workers. You could use something like Thaw and Freeze to serialize perl
data types as well.
I haven't thoroughly thought through this design so there may be some
'gotchas' but my hope is to save you a few days of Perl IPC Frustration.
The obvious caveat here is avoiding memory bloat by being conservative in
the amount of data you jam into shared dicts. I foresee you will have
issues using internal_redirect (I dont have the docs in front of me), so
you may need to be creative here as the API is limited. I have a soft spot
for perl but this module leaves a lot to be desired. You must be thoughtful
in your design as to what will and will not block.
As a final thought, have you looked into
http://zzzcpan.github.io/nginx-perl/ ? this project appears to be in need
of love and if memory serves makes some changes to nginx core which
prevents upgrades, however, this project seems to support a lot of async
perl operations that would make life easier.
On Wed, May 14, 2014 at 10:06 AM, David Coutadeur
<dcoutadeur at linagora.com>wrote:
> Le 14/05/2014 18:58, Maxim Dounin a écrit :
>> On Wed, May 14, 2014 at 06:47:26PM +0200, David Coutadeur wrote:
>>> I am trying to build a perl access handler module into nginx, thanks to
>>> API :
>>> but I have some difficulties to do so.
>>> Indeed, I would need some tools like
>>> - a mean to share variables between handlers,
>>> - a mean to call my handler at access phase.
>>> For example, I have made a basic handler in lUA with this more complete
>>> Does anybody have ideas on how to achieve the two functionnalities in the
>>> current perl API ?
>>> Will this lack of features for perl API be filled in the future ? In a
>>> future ? Or do you advise other actions ?
>> Sharing variables (I believe you really want to do so between
>> requests) can be done using normal Perl things like global
>> variables (or, if you want many workers to share the same data,
>> using shared memory, see various perl modules available on CPAN).
> Yes, this is what I want to do. For example, loading some parameters from
> a config file, and store them in a shared memory place. Do you have some
> advice on a CPAN module which works best with nginx ?
>> Calling the handler at access phase isn't something you can do
>> without modifications of the code. On the other hand, it may be a
>> good idea to use auth request module instead, and write a
>> subrequest handler in embedded perl.
>>  http://nginx.org/en/docs/http/ngx_http_auth_request_module.html
> Ok, thank you, I will try this !
> nginx mailing list
> nginx at nginx.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nginx