Forum: NGINX perl module for nginx

3defb520d61fe3179dd13973e1fadef5?d=identicon&s=25 David Coutadeur (Guest)
on 2014-05-14 18:47
(Received via mailing list)
Hello,

I am trying to build a perl access handler module into nginx, thanks to
this API :
http://nginx.org/en/docs/http/ngx_http_perl_module.html
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
API :
http://wiki.nginx.org/HttpLuaModule

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
near future ? Or do you advise other actions ?


Many thanks,

David
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-05-14 18:59
(Received via mailing list)
Hello!

On Wed, May 14, 2014 at 06:47:26PM +0200, David Coutadeur wrote:

> - a mean to call my handler at access phase.
>
> For example, I have made a basic handler in lUA with this more complete API
> :
> http://wiki.nginx.org/HttpLuaModule
>
> 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 near
> 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).

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[1] instead, and write a
subrequest handler in embedded perl.

[1] http://nginx.org/en/docs/http/ngx_http_auth_reques...

--
Maxim Dounin
http://nginx.org/
3defb520d61fe3179dd13973e1fadef5?d=identicon&s=25 David Coutadeur (Guest)
on 2014-05-14 19:07
(Received via mailing list)
Le 14/05/2014 18:58, Maxim Dounin a crit :
>> but I have some difficulties to do so.
>> current perl API ?
>> Will this lack of features for perl API be filled in the future ? In a near
>> 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[1] instead, and write a
> subrequest handler in embedded perl.
>
> [1] http://nginx.org/en/docs/http/ngx_http_auth_reques...
>

Ok, thank you, I will try this !

David
Ba5061f1803f9ab0cfc3d53366d49546?d=identicon&s=25 Lord Nynex (Guest)
on 2014-05-16 02:36
(Received via mailing list)
I'm a bit pressed for time but want to throw out a few incomplete
thoughts
on this.

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
shared dictionary.
- 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.