rlm_python and threading

Andrew Parisio parisioa at gmail.com
Wed Mar 25 03:27:30 CET 2015


I'm working with rlm_python in FreeRadius 2.2.6 and with 20 simultaneous
eapol_test threads running I was only getting 5-6 requests/second.  This
got me wondering how FreeRadius and rlm_python handle threading.   So to
make sure it wasn't related to my database calls or anything else I wrote a
simple radiusd_module.py with no external dependencies/calls that instantly
returned OK and it was handling 275 requests/second.

Now I'm doubting my requests are being processed in parallel so I modified
my radiusd_module.py to have a 1 second sleep between starting to process a
request and returning OK.   The module looks something like this:

  import radiusd
  import time

  def instantiate(p):
      # do something
      return 0

  def array_to_dict(array):
      my_dict = {}
      for t in array:
          # strip any quotes off of the beginning & end
          my_dict[t[0]] = t[1].lstrip('"').rstrip('"')
      return my_dict

  def post_auth(p):
      my_dict = array_to_dict(p)
      print "***** Start %s" % my_dict['NAS-Port-Id']
      time.sleep(1)
      print "***** End %s" % my_dict['NAS-Port-Id']
      return radiusd.RLM_MODULE_OK


Then I set two copies of eapol_test in an infinite loop sending
NAS-Port-Id's of 1 and 2 so I could see what radius.log looked like.

The hypothesis being if it's properly threaded I should get this:
***** Start 1
***** Start 2
==== Pause 1 second
***** End 1
***** End 2
... repeat



I ran the the two eapol_test threads against radius and the output looks
like this:
tail radius.log -f | grep "\*\*\*\*\*"
***** Start 1
==== Pause 1 second <-- not output, just a literal 1 second wait from
time.sleep()
***** End 1
***** Start 2
==== Pause 1 second <-- not output, just a literal 1 second wait from
time.sleep()
***** End 2
.... and so on,

>From this I can see that requests handled by rlm_python are being served by
a single thread rather than multiple/parallel threads.  Does anybody have
any experience with rlm_python.py and/or know what I might be doing wrong?

Thanks!

Andrew

P.S. Latency from my development machine at my desk to Dynamodb in AWS is
~80ms, **which won't be the case for prod**, which is why I was only
getting 5-6 requests/second.  but I'd still like to be able to handle
hundreds of requests/s per production host (obviously the hosts will need
to be sized appropriately).


More information about the Freeradius-Users mailing list