-
Notifications
You must be signed in to change notification settings - Fork 50
Parallel Libtrace HOWTO: Processing Threads
A processing thread is a thread that receives packets from the input source, performs some amount of processing or analysis on that packet and then may publish some results to the reporter thread. The number of processing threads is configurable but be aware that more threads is not necessarily going to result in better performance, especially if most of those threads are not doing any work. There will always be at least one processing thread in a parallel libtrace program and each processing thread will automatically halt when libtrace stops reading packets from the input source.
Thinking about our scenario, our processing thread needs to identify UDP packets, increment a packet counter by one and increment a byte counter by the payload size of the packet. Each thread should have its own local packet and byte counters, so we aren't having to contend with other threads to update the counters. When our thread comes to an end, we want to publish those counters to the reporter so that it can tally and print our final result.
Enough design; time to start writing some code! Let's start with a starting callback.