[RADIATOR] Hooks and Persistent Database connections

Heikki Vatiainen hvn at open.com.au
Tue Sep 11 14:30:08 CDT 2012


On 09/11/2012 07:07 PM, Johnson, Neil M wrote:

> Is there another way to maintain a persistent connection to a database
> between calls to hooks ?

You could consider this: Add e.g, AuthBy SQL, AuthLogSQL or some other
SQL based clause in the configuration file. Make sure the clause has
Identifier. Then do this in the hook (using AuthBy as an example):

my $identifier = 'authby-for-hook';
my $db = Radius::Configurable::find('AuthBy', $identifier);
my $query = "SELECT ...";
my $sth = $db->prepareAndExecute($query); # Can also use bind variables
...

Since prepareAndExecute (see SqlDb.pm) does connect and reconnect when
needed you can let it take care of connection management. You can also
easily set Timeout and other parameters. Just add them in the clause you
have chosen.

> The issue is that the DBI->connect_cached() statement I'm using makes a
> DBD->ping call to the database to check the connection and Our database
> server people our complaining that the statement is causing a high CPU
> load on their SQL Server cluster.

SqlDb already caches connections so the above could be the easiest and
quickest way to maintain persistent connections from hooks. It can also
make hooks shorter since they do not have to do connection, timeout and
other stuff SqlDb already does.

Thanks,
Heikki

-- 
Heikki Vatiainen <hvn at open.com.au>

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald,
Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS,
TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS,
NetWare etc.


More information about the radiator mailing list