The standard fix for a slow FreeRADIUS server is a faster database. Sometimes the better fix is no database at all.
Arran Cudbard-Bell, CTO and FreeRADIUS Principal Architect, InkBridge Networks
When a FreeRADIUS system starts missing its SLA, the first piece of advice is almost always the same: fix your database. Why? If the database is slow, then that is factor which is limiting performance. A database that can only handle 2K updates per second just can’t keep up with a production network which needs 10K updates per second.
There's a related question worth asking, though: does this particular lookup need to hit the database at all? Often it doesn't.
There are a few ways to bypass the database. One is to have portions of the policies in memory, such as with the “files” module. Another is to add caching. Both solutions can work independently, or together. People tend to reach for the solution that they’re familiar with, rather than the one that’s the right solution for the problem. That is,both solutions work, they just solve different problems.
The files module is for data you already own and rarely change. It’s a simple, fast, in-memory lookup table.
The cache module stores data which is created dynamically. Usually, data that’s expensive to create, but easy to store.
Does this particular lookup need to hit a database at all?
Often it doesn't.
The files module
The "files” module is one of the oldest modules in the codebase. The configuration syntax can be traced back to the original Livingston RADIUS server in 1993, when “the database” meant a text file with one entry per user. Where the original RADIUS servers read the entire file for every packet (which is slow!), FreeRADIUS reads it once at startup, and then saves a copy in memory.
The FreeRADIUS files module documentation, contains a long description of its functionality and configuration, the important points are that FreeRADIUS loads the file, saves a copy, and index the data based on the most appropriate key. Depending on the data you need to store, it automatically uses hash tables, Red-Black trees, or Patricia tries.
Once it's loaded, a single lookup is in-memory and fast. There's no disk or network round trip involved. We’ve tested it with millions of entries, and its performance is essentially the same as tests with just tens of entries.
The clearest use case is key-value lookups which rarely change. For example, mapping a two-letter state code to a service region, or a subscriber tier to a set of reply attributes. In most cases, tou already know the full set of possible keys, and you just need to use the key to get the data.
In contrast, a database of users is changing all of the time. Users are added and deleted every day, or even every minute. That’s a good use-case for an SQL or LDAP database, not so much for the “files” module.
So while the "files" module isn't a good database for users, it is a good database for large amounts of data that change rarely. To be fair, in-memory key-value lookups pretty much always beat “over the network” queries for performance and latency.
The trade-off is that the “files” module configuration is a snapshot. If you change it's contents, the server keeps serving the old data until it's reloaded. That’s fine for data you update rarely through a deliberate change process, but it’s a poor fit for anything that needs to reflect a live system with minute-by-minute changes. That’s where the “cache” module is a better choice.
The cache module
The "cache" module solves a different problem. It’s best at saving the result of an expensive lookup or calculation, that you’d rather not repeat. For example, if there is a substantial amount of data returned via an SQL query, those queries can be slow. Adding some caching can result in significant performance improvements.
The design is simple. The first request pays the full cost of a query against SQL, LDAP, or a REST endpoint. Once the data is returned, the cache module stores that result,. Every subsequent request within the cache “time-to-live" then gets served from the cache (local, in-memory), rather than requiring an expensive round trip over the network to database.
For people who think that databases are fast, you’re right, most are. But some databases are slow. Our university customers regularly have issues where their student database (AD) can handle only a hundred or so authentications a second, whereas the demand from students is to re-authenticate after every class. That requirement can easily reach thousands of authentications a second. And for most students, their credentials don’t change on an hourly basis. So a cache here can save hundreds of thousands of queries to a slow database.
The benefit of this approach is that the backend still answers the first request. It just isn't asked the same question again (and again) while the cached answer is still valid.
The FreeRADIUS cache module documentation has a number of options for where the cache is stored, each with different trade-offs:
rbtree stores entries in memory on a single server. It's fast and simple, but the data disappears if that instance restarts.
memcached shares a cache across a one or more memcache servers.
redis shares a cache across a one or more redis servers.
The external memcache and redis stores are still faster than a database such as Active Directory, because they do a lot less work. Plus, those database can be used to store TLS information for “fast session resumption”, with EAP. That configuration allows the cache to be saved across restarts of the RADIUS server, which means that a restart doesn’t affect the cache!
The “cache” module also has a “time to live” (ttl) setting which applies to all cache storage options. That configuration controls how long a cache entry persists. For an enterprise or university, a ttl of a few hours is reasonable. That’s long enough to cactch the majority of re-authentications, and short enough that it doesn’t cause problems for people who change their passwords or have their accounts suspended.
Another use-case for caching that we’ve seen is for device authentiction and authorization, such as with TACACS+. In those situations authorization such as group membership rarely changes, but it gets checked often. The cache module allows you to skip expensive and slow database lookups for an hour, or for a data, depending on what you need. During that time, every later query can be a local memory read instead of an expensive database round trip.
A cache can also increase system stability in the face of network problems. If the database does offline, such as during a maintenance window, most requests will be handled by the cache, and will allow users to get online as normal. Only a small number of users who don’t have cached entries will be affected by that outage.
Worth subscribing to.
Worth reading.
Our weekly newsletter covers network authentication tips, how-tos, security vulnerabilities, free resources, standards updates, and industry news. (All stuff you should stay up to date on!)
Should I use the files module or the cache module?
Both of the modules are fast, which is the point of using them. What separates them is how often the data gets updated.
If you maintain the data yourself, in a format you control, changing on a schedule you manage: use the files module. You already have the full dataset, so you might as well have a full copy locally.
If the data comes from a system you don’t control, or is expensive enough to fetch that repeating the query is the actual bottleneck: use the cache module, with a time-to-live that matches how fast that original data gets changed.
If losing a cached value to a restart or failover would be a real problem, use redis. If it wouldn’t, rbtree is simpler, and is one less service to operate.
If more than one RADIUS server needs to have the same static configuration, the files module requires you to ensure that you use guarantee identical files across every server. This is a minor deployment problemm if you need that.
If more than one RADIUS server needs access to changing data, the cache module (backed by memcached or redis) is the ideal solution. It’s part of a wider pattern that we cover in Scaling your RADIUS ecosystem.
None of the bullet points above is a hard rule. They’re really just a set of questions that you should ask yourself, and have and answer to, before reaching for either module.
Will caching fix a FreeRADIUS database bottleneck?
Caching doesn’t fix things if the real problem is a missing database index, a schema that forces a full table scan for every qeury, or a connection pool sized for the traffic rate that you had two years ago. Caching just postpones when the underlying problem shows up again. Database issues are a separate problem with separate fixes, which we’ve covered in Database design principles for RADIUS systems.
Another common attempt to “fix” a slow database is to update FreeRADIUS to raise it’s connection limits or thread limits. As we said at the start of the article, changing the FreeRADIUS configuration doesn’t help when the real problem is a slow backend database. Opening more connections to a database that's already overloaded just increases the load on the database. So when FreeRADIUS complains that the database is slow, the answer isn’t to increase the load on the database; it’s to either decrease the load on the database (via the “files” or “cache” modules). If you can’t do that, the only other choice is to make the database faster.
Caching also involves its own judgement calls. The best value for a time-to-live is depends on your local requirements. A value which is too low means that you’re not offloading enough work from the database. A value which is too high means that the user can get stale answers for “too long” a period of time.
The summary of all of the above is that most of the limits to FreeRADIUS performance are the database. And database performance is limited by the number of queries that it has to answer. Repeated queries are wasteful, so the files and cache modules exist to keep that number down. Using either module can offload signficant amounts of work from the database, increase system performance, and increase system stability. Which solution you pick is up to you.
Need more help?
If your team is wrestling with network configuration, a troubleshooting problem you cannot resolve, or a system that needs to be more resilient, we can help. InkBridge Networks has 25 years of expertise - we wrote the standards, maintain FreeRADIUS, and have seen every failure mode there is. Reach out to request a quote.
Related Articles
My FreeRADIUS server is slow. What's wrong?
If you are encountering performance issues with FreeRADIUS, the first thought is usually to blame FreeRADIUS. In fact, it’s always the database which is the source of a system slowdown. Well, maybe not always, but 99 times out of a 100, it’s the database. It is extremely unlikely that FreeRADIUS is the culprit when you notice slow performance. Here’s how we know.
Database design principles for RADIUS systems
Database design is often overlooked as a critical element of a RADIUS ecosystem. In practice, when we work with our clients, we usually spend the bulk of our time optimizing the database architecture. Our time spent on FreeRADIUS is small in comparison. Why? Because the difference between a fast, reliable RADIUS system and a slow, unstable one is almost always the database.