Migrating to threaded rlm_perl
Hi everyone! Please, help me with understanding of concept how to rewrite my perl module to work with threaded perl. Now it looks like this: my %options_pools = (create=>1, exclusive=>0, mode=>0644, destroy=>1); tie my %pooldb, 'IPC::Shareable', $pools_glue, { %options_pools } or die "Tie failed: $!\n"; ... code to fullfill shared segment ... sub post_auth { ... $RAD_REPLY{'Framed-IP-Address'} = "$pooldb{$rpool}{$RAD_REQUEST{'Calling-Station-Id'}} ... %up= fetch_url("$https_host","$https_xml","$RAD_REQUEST{'User-Name'}"); } sub fetch_url { ... using Net::HTTP i retrieve some additional stuff from billing. ... } While non-threaded perl it works as expected. But threading breaks creation of Shared memory (cuz it want to do it for every thread). I also wonder, do i need to post &fetch_url inside CLONE sub or not. So, the main question: is there any part of code in rlm, that suppose to run only once ( create shared memory in my situation) or how to correctly solve problem with IPC within the confines of freeradius. Thx! -- View this message in context: http://freeradius.1045715.n5.nabble.com/Migrating-to-threaded-rlm-perl-tp450... Sent from the FreeRadius - User mailing list archive at Nabble.com.
Energ <ponch@ponch.ru> wrote:
Please, help me with understanding of concept how to rewrite my perl module to work with threaded perl.
Now it looks like this:
[snipped thread unsafe code]
While non-threaded perl it works as expected. But threading breaks creation of Shared memory (cuz it want to do it for every thread). I also wonder, do i need to post &fetch_url inside CLONE sub or not. So, the main question: is there any part of code in rlm, that suppose to run only once ( create shared memory in my situation) or how to correctly solve problem with IPC within the confines of freeradius.
You should have a read of: http://perldoc.perl.org/perlmod.html#BEGIN,-UNITCHECK,-CHECK,-INIT-and-END I would recommend you do not use IPC::Shareable and instead look to use BerkeleyDB instead with locks...also means whatever in in your hash is remembered across FreeRADIUS restarts. Cheers [1] http://search.cpan.org/dist/BerkeleyDB/BerkeleyDB.pod -- Alexander Clouter .sigmonster says: BOFH excuse #192: runaway cat on system.
Thanks, Alexander! But, would it make any difference by using BEGIN{} block for creating shared memory segment? Wont threaded rlm_perl process this section in every thread it starts? -- View this message in context: http://freeradius.1045715.n5.nabble.com/Migrating-to-threaded-rlm-perl-tp450... Sent from the FreeRadius - User mailing list archive at Nabble.com.
Energ <ponch@ponch.ru> wrote:
But, would it make any difference by using BEGIN{} block for creating shared memory segment? Wont threaded rlm_perl process this section in every thread it starts?
Threaded to FreeRADIUS means those methods you define are reentrant. IIRC BEGIN{} is called only when rlm_perl fires up, afterwards your methods are called whenever required, pre-emptively. Cheers -- Alexander Clouter .sigmonster says: You mean you don't want to watch WRESTLING from ATLANTA?
Seems like BEGIN{} block did the trick. Thanks, Alexander. I also moved from IPC to SQLite. But now i am faced with another problem - memory leak. For about an hour of uptime i get this: 5575 radius 2874M 2870M sleep 59 0 0:01:25 1.2% radiusd/9 and it countinues to grow. thread pool: start_servers = 5 max_servers = 32 min_spare_servers = 3 max_spare_servers = 20 max_requests_per_server = 300 perl threads: max_clones = 30 start_clones = 5 min_spare_clones = 2 max_spare_clones = 64 cleanup_delay = 1 max_request_per_clone = 100 what can cause such behaviour? radiusd -v radiusd: FreeRADIUS Version 2.1.11, for host sparc-sun-solaris2.10, built on Jun 20 2011 at 16:16:34 Thanks! В Mon, 20 Jun 2011 19:15:49 +0100 Alexander Clouter <alex@digriz.org.uk> пишет:
Energ <ponch@ponch.ru> wrote:
But, would it make any difference by using BEGIN{} block for creating shared memory segment? Wont threaded rlm_perl process this section in every thread it starts?
Threaded to FreeRADIUS means those methods you define are reentrant. IIRC BEGIN{} is called only when rlm_perl fires up, afterwards your methods are called whenever required, pre-emptively.
Cheers
Rolling back to Freeradius 2.1.10 solved problem with memory leaks. I did not debug it, but it seems like accountig problem in 2.1.11. -- View this message in context: http://freeradius.1045715.n5.nabble.com/Migrating-to-threaded-rlm-perl-tp450... Sent from the FreeRadius - User mailing list archive at Nabble.com.
participants (3)
-
Alan DeKok -
Alexander Clouter -
Energ