Skip to contentSkip to conversation

A top 10 statistics module?

DISCUSSION Wang Jian 2 participants 3 messages Apr 20, 2005 netfilter

lore
Share & tools
lore

Wang Jian

author
#0 lore raw

Hi,

I have a customer who needs functionality that list top 10 hosts (listener or talker). It normally done in userspace, but in this case, the 10 hosts is for a tc class. Moreover, it is expected that 2 or more tc classes' top 10 are collected at the same time.

So I think this is better handled in kernel space, because the classid and/or nfmark is only seen in kernel space.

The idea is that a rule like

-m mark --mark 0x1 -j TOPHOST --count 10 --name FILENAME

will collect top10 IPs (using conntrack flow account) and export the information under /proc/net/stat/top10/FILENAME based on the source address. (You may need add -i to indicate the direction)

Of course, the top10 can be used to match any other criteria beside the nfmark. It can even collect top10 of all traffic.

Top10 is used to monitor a while and then disabled. It could be expensive, but is useful to investigate.

I will implement it anyway to complete the task, but before I code, I am willing to listen to any one who has comment and suggestion.

Signature · 1 line
  lark
#1 lore raw
Quoted 5 lines · Wang Jian

Top10 is used to monitor a while and then disabled. It could be expensive, but is useful to investigate.

I will implement it anyway to complete the task, but before I code, I am willing to listen to any one who has comment and suggestion.

To be generally useful, the table must be bounded. That will result in inaccurate order statistics, but often that doesn't matter much, if the table is an order of magnitude or two larger than the required order statistic, (i.e., 100-1000 entries for estimating the top 10).

Given that the table must be bounded, there needs to be a replacement policy once it fills up. The best choice of replacement strategy of course depends on the distribution of new entries; the problem is similar to that of the code table management in certain data compression algorithms. Heuristics and data structures tend to be somewhat intimate, as fast updates are required.

A common heuristic is to prioritize the entries via a scaled frequency that decays with a time (or packet count, etc.) scaling constant, and replace the lowest frequency members in the table with the new entries. This heuristic lends itself to being implemented with a heap-based priority queue whose top is the next entry to be expired.
Complexity: O(log N)

Other heuristics derive from various queuing models, the simplest being "move-to-front" -- every time an entry is referenced, it is moved to the front of the active list; entries are expired from the tail of the list. Complexity: O(1)

In the distant past I've used the scaled frequency heuristic to good effect on long time-series data.

Regards,

Bill Rugolsky

author
#2 lore raw

Hi Bill Rugolsky Jr.,

Thanks for your input.

Quoted 19 lines · Bill Rugolsky Jr.
Quoted 5 lines · Wang Jian

Top10 is used to monitor a while and then disabled. It could be expensive, but is useful to investigate.

I will implement it anyway to complete the task, but before I code, I am willing to listen to any one who has comment and suggestion.

To be generally useful, the table must be bounded. That will result in inaccurate order statistics, but often that doesn't matter much, if the table is an order of magnitude or two larger than the required order statistic, (i.e., 100-1000 entries for estimating the top 10).

Given that the table must be bounded, there needs to be a replacement policy once it fills up. The best choice of replacement strategy of course depends on the distribution of new entries; the problem is similar to that of the code table management in certain data compression algorithms. Heuristics and data structures tend to be somewhat intimate, as fast updates are required.

Quoted 6 lines

A common heuristic is to prioritize the entries via a scaled frequency that decays with a time (or packet count, etc.) scaling constant, and replace the lowest frequency members in the table with the new entries. This heuristic lends itself to being implemented with a heap-based priority queue whose top is the next entry to be expired.
Complexity: O(log N)

This is the first thing appears in my mind :)

Quoted 5 lines

Other heuristics derive from various queuing models, the simplest being "move-to-front" -- every time an entry is referenced, it is moved to the front of the active list; entries are expired from the tail of the list. Complexity: O(1)

This is very easy to implement. I will try this first :)

Quoted 7 lines

In the distant past I've used the scaled frequency heuristic to good effect on long time-series data.

Regards,

Bill Rugolsky

Signature · 1 line
  lark