matching performance

Glenn Satchell glenn.satchell at uniq.com.au
Fri Sep 24 11:34:28 UTC 2010


On 09/24/10 06:02, Adam Moffett wrote:
> I want to match several clients and give them a different option.
>
> Is it better to do it this way:
>
> if option agent.remote-id=0A:00:3E:F0:5C:84 {
> option domain-name-servers 127.0.0.1;
> }
> if option agent.remote-id=0A:00:3E:F0:7C:7C {
> option domain-name-servers 127.0.0.1;
> }
> if option agent.remote-id=0A:00:3E:F0:6D:3E {
> option domain-name-servers 127.0.0.1;
> }
>
> Or this way:
>
> if (option agent.remote-id = 0A:00:3E:F0:5C:84) or
> (option agent.remote-id=0A:00:3E:F0:7C:7C) or
> (option agent.remote-id=0A:00:3E:F0:6D:3E)
> { option domain-name-servers 127.0.0.1; }
>
> I only ask because there could be a scenario where my "several" clients
> becomes "several hundred".

There's a few other ways to do it. In your first example you evaluate 
the equality against every string, every time. You could turn it into a 
linear search using elsif, eg

if option agent.remote-id=0A:00:3E:F0:5C:84 { ... }
elsif option agent.remote-id=0A:00:3E:F0:7C:7C { ... }

which would stop after it matched.

A sub-class is probably going to be more efficient as it uses a hashed 
lookup. Of course, unless there were many 000's of such entries it's not 
likely to make much difference either way on decent hardware. eg:

class "dns1" {
	match option agent.remote-id;
	option domain-name-servers 127.0.0.1;
}
sub-class "dns1" 0A:00:3E:F0:5C:84;
sub-class "dns1" 0A:00:3E:F0:7C:7C;
sub-class "dns1" 0A:00:3E:F0:6D:3E;

Of course you can have as many different classes and sub-classes as 
required. You could even have the sub-class statements in a separate 
file that you included, if you wanted to generate them with a script, 
for example.

regards,
-glenn



More information about the dhcp-users mailing list