Re: rlm_perl and threads

2012-11-15 Thread Edgar Fuß
To answer my own question:
> In the module init code, can I tell whether I'm in the threading case or not?
Yes: use Config and check $Config{useithreads}.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: rlm_perl and threads

2012-11-14 Thread Edgar Fuß
Thanks, this has been very helpful.

If I read the source correctly, it works as follows:
-- A "global" interpreter is created that runs the module initialization code.
-- When a perl function is going to be called, the global interpreter is used 
in the non-threading case. In the threading case, if necessary, a thread-local 
interpreter is created by cloning the global one.
So, in the non-threading case, I would have to perform initialization tasks 
like opening a database connection in the module init code. In the threading 
case, I have do to that in CLONE().
In the module init code, can I tell whether I'm in the threading case or not? 
It's probaby no harm besides a waste of resources to also do the full init 
there in the threading case, but I would like to avoid that if easily possible.

> Threading is not done in debug mode (-X), start your freeradius in normal 
> mode to test multithreading.
I think this should be documented since one is always urged to test in debug 
mode.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: rlm_perl and threads

2012-11-05 Thread Sander Eerdekens
The old wiki used to contain more information on this.
I'm currently in the process of making our rlm_perl module multithreaded as 
well.

Some pointers:
perl -V | grep -i multipl
...
useithreads=define, usemultiplicity=define
  Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS

check your multiplicity here. Multiplicity causes one perl process to be 
started, with multiple perl interpreters inside.

Add a CLONE function to your perl script (yes, all in caps).
The CLONE function is run every time a new perl interpreter is started. What 
happens is all existing variables are copied to the new interpreter when a new 
thread is started.
In this function you can adjust values that should be unique for each thread 
(like database handlers).

The number of threads are controlled trough the max_servers and max/min spare 
servers  in your radiusd.conf

Threading is not done in debug mode (-X), start your freeradius in normal mode 
to test multithreading.

AFAIK the above information is correct and recent.

Kind regards

Sander Eerdekens
Informatiesystemen
Systeembeheer & Ondersteuning

san...@uzleuven.be
UZ Leuven | campus Gasthuisberg | Herestraat 49 | B - 3000 Leuven | 
www.uzleuven.be




--

Message: 5
Date: Mon, 05 Nov 2012 14:01:56 +
From: Phil Mayers 
To: freeradius-users@lists.freeradius.org
Subject: Re: rlm_perl and threads
Message-ID: <5097c6d4.9070...@imperial.ac.uk>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 05/11/12 13:36, Edgar Fu? wrote:
>> Yes. Likely, even.
> Thanks. So will these then be two distinct Perl interpreters or two instances
> of the same Perl interpreter? From the Perl script's point of view, what will
> the two instances share?
> Can you hint me to any documentation covering this?

I'm not aware of any docs. You might need to refer to the source.

In particular, the USE_ITHREADS #define seems to control how the perl 
interpreter is created/allocated/used. I'm not familiar enough with perl 
to understand the code, personally. See here:

https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_perl/rlm_perl.c#L254

...and the rest of that file.

-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: rlm_perl and threads

2012-11-05 Thread Phil Mayers

On 05/11/12 13:36, Edgar Fuß wrote:

Yes. Likely, even.

Thanks. So will these then be two distinct Perl interpreters or two instances
of the same Perl interpreter? From the Perl script's point of view, what will
the two instances share?
Can you hint me to any documentation covering this?


I'm not aware of any docs. You might need to refer to the source.

In particular, the USE_ITHREADS #define seems to control how the perl 
interpreter is created/allocated/used. I'm not familiar enough with perl 
to understand the code, personally. See here:


https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_perl/rlm_perl.c#L254

...and the rest of that file.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: rlm_perl and threads

2012-11-05 Thread Edgar Fuß
> Yes. Likely, even.
Thanks. So will these then be two distinct Perl interpreters or two instances 
of the same Perl interpreter? From the Perl script's point of view, what will 
the two instances share?
Can you hint me to any documentation covering this?
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: rlm_perl and threads

2012-11-05 Thread Phil Mayers

On 05/11/12 12:34, Edgar Fuß wrote:

Sorry if this sounds like a stupid question with an obvious answer, but I
could not easily find this documented.

If I have an rlm_perl script, is it possible that multiple instances of it
are running concurrently due to FreeRADIUS' threading?


Yes. Likely, even.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html