Hi,
I'm trying to embed perl into my server named nginx. The server uses
event-driven architecture and works with many non-blocking connections
in each worker processes. I want to make compatible it to mod_perl as much
as possible, however, I understand that non-blocking connections do not
allow to implement many mod_perl features.
As I understand I should build perl with MULTIPLICITY support.
Then I can create interpreters pool, and at run-time I will get
the free interpreter and use PERL_SET_CONTEXT() to activate it before
any interpreter action.
Right now I'm experimenting with single interpreter. I've written
small module, it's very similar to mod_perl's one: s/Apache/nginx/.
----------
package hello;
use nginx;
sub handler {
my $r = shift;
$r->send_http_header;
return OK if $r->header_only;
$uri = $r->uri;
$r->print("hello!\n", "URI: \"$uri\"\n");
return OK;
}
1;
__END__
----------
nginx does not copy values but uses the same memory as perl scalars.
It also increments references of each scalar. nginx stores the chain
of the buffers and returns. The real transfer will be after some time.
The request is treated as done on the perl side and interpreter is free
and can process the next request. However, I've found that next request
may corrupt memory of 'URI: "$uri"\n' scalar of the first request.
The question is how to unshare 'URI: "$uri"\n' memory ?
Or how to know what scalar value may be safely shared (as "hello!\n") ?
By the way, I found that simple sequence:
perl = perl_alloc();
perl_construct(perl);
perl_destruct(perl);
perl_free(perl);
leaves 16K memory leak.
I'm using "perl v5.8.7 built for i386-freebsd-64int".
Igor Sysoev
http://sysoev.ru/en/
Thread Next