<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Justin asked an interesting question today, how does this affect performance on the manager? That is where we are feeling a lot of pain with select().
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Apr 11, 2017, at 7:41 PM, Siwek, Jon &lt;<a href="mailto:jsiwek@illinois.edu" class="">jsiwek@illinois.edu</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">I recently got a minimal CAF-based run loop for Bro working, did crude performance comparisons, and wanted to share.<br class="">
<br class="">
The approach was to measure average time between calls of net_packet_dispatch() and also the average time it takes to analyze a packet. &nbsp;The former attempts to measure the overhead imposed by the loop implementation and the later just gives an idea of how significant
 a chunk of time that is in relation to Bro’s main workload. &nbsp;I found that the overhead of the loop can be ~5-10% of the packet processing time, so it does seem worthwhile to try and keep the run loop overhead low.<br class="">
<br class="">
Initial testing of the CAF-based loop showed the overhead increased by ~1.8x, but there was still a major difference in the implementations: the standard Bro loop only invokes its IOSource polling mechanism (select) once every 25 cycles of the loop, while the
 CAF implementation’s polling mechanism (actor/thread scheduling &#43; messaging &#43; epoll) is used for every cycle/packet. &nbsp;As one would expect, by just trivially spinning the main process() function in a loop for 25 iterations, the overhead of the CAF-based loop
 comes back into line with the standard run loop.<br class="">
<br class="">
To try and better measure the actual differences related to the polling mechanism implementation, I quickly hacked Bro’s standard runloop to select() on every packet instead of once every 25th and found that the overhead measures &#43;/- 10% within the 1.8x overhead
 increase of the initial CAF-based loop. &nbsp;So is the cost of the extra system call for epoll/select per packet the main thing to avoid? &nbsp;Sort of. &nbsp;I again hacked Bro’s standard loop to be able to use either epoll or poll instead of select and found that those
 do better, with the overhead increase being about 1.3x (still doing one “poll” per packet) in relation to the standard run loop. &nbsp;Meaning there is some measurable trend in polling mechanism performance (for sparse # of FDs/sources): poll comes in first, epoll
 second, with CAF and select about tied for third.<br class="">
<br class="">
Takeaways:<br class="">
<br class="">
(1) Regardless of runloop implementation or polling mechanism choices, performing the polling operation once per packet should probably be avoided. &nbsp;In concept, it’s an easy way to get a 2-5% speedup in relation to total packet processing time.<br class="">
<br class="">
(2) Related to (1), but not in the sense of performance, is that even w/ a CAF-based loop it still seems somewhat difficult to reason about the reality of how IOSources are prioritized. &nbsp;In the standard loop, the priority of an IOSource is a combination of
 its “idle” state, the polling frequency, and a timestamp, which it often chooses arbitrarily as the “time of last packet”, just so that it gets processed with higher priority than subsequent packets. &nbsp;Maybe the topic of making IOSource prioritization more
 explicit/well-defined could be another thread of discussion, but my initial thought is that the whole IOSource abstraction may be over-generalized and maybe not even needed.<br class="">
<br class="">
(3) The performance overhead of a CAF-based loop doesn’t seem like a showstopper for proceeding with it as a choice for replacing the current loop. &nbsp;It’s not significantly worse than the current loop (provided we still throttle the polling ratio when packet
 sources are saturated), and even using the most minimal loop implementation of just poll() would only be about a 1% speedup in relation to the total packet processing workload.<br class="">
<br class="">
Just raw data below, for those interested:<br class="">
<br class="">
I tested against the pcaps from <a href="http://tcpreplay.appneta.com/wiki/captures.html" class="">
http://tcpreplay.appneta.com/wiki/captures.html</a><br class="">
(I was initially going to use tcpreplay to test performance against a live interface, but decided reading from a file is easier and just as good for what I wanted to measure).<br class="">
Numbers are measured in “ticks”, which are equivalent to nanoseconds on the test system.<br class="">
Bro and CAF are both compiled w/ optimizations.<br class="">
<br class="">
bigFlows.pcap, 1 “poll&quot; per packet<br class="">
--------------------------<br class="">
poll<br class="">
('avg overhead', 1018.8868239999998)<br class="">
('avg process', 11664.4968147)<br class="">
<br class="">
epoll<br class="">
('avg overhead', 1114.2168096999999)<br class="">
('avg process', 11680.6078816)<br class="">
<br class="">
CAF<br class="">
('avg overhead', 1515.9933343999996)<br class="">
('avg process', 11914.897109200003)<br class="">
<br class="">
select<br class="">
('avg overhead', 1792.8142910999995)<br class="">
('avg process', 11863.308550400001)<br class="">
<br class="">
bigFlows.pcap, Polling Throttled to 1 per 25 packets<br class="">
---------------------------<br class="">
poll<br class="">
('avg overhead', 772.6118347999999)<br class="">
('avg process', 11504.2397625)<br class="">
<br class="">
epoll<br class="">
('avg overhead', 814.4771509)<br class="">
('avg process', 11547.058394900001)<br class="">
<br class="">
CAF<br class="">
('avg overhead', 847.6571822)<br class="">
('avg process', 11681.377972700002)<br class="">
<br class="">
select<br class="">
('avg overhead', 855.2147494000001)<br class="">
('avg process', 11585.1111236)<br class="">
<br class="">
smallFlows.pcap, 1 “poll&quot; per packet<br class="">
----------------------------<br class="">
poll<br class="">
('avg overhead', 1403.8950280800004)<br class="">
('avg process', 22202.960570839998)<br class="">
<br class="">
epoll<br class="">
('avg overhead', 1470.0554376)<br class="">
('avg process', 22210.3240474)<br class="">
<br class="">
select<br class="">
('avg overhead', 2305.6278429200006)<br class="">
('avg process', 22549.29251384)<br class="">
<br class="">
CAF<br class="">
('avg overhead', 2405.1401093399995)<br class="">
('avg process', 23401.66596454)<br class="">
<br class="">
smallFlows.pcap, Polling Throttled to 1 per 25 packets<br class="">
-----------------------------<br class="">
poll<br class="">
('avg overhead', 1156.0900352)<br class="">
('avg process', 22113.8645395)<br class="">
<br class="">
epoll<br class="">
('avg overhead', 1192.37176)<br class="">
('avg process', 22000.2246757)<br class="">
<br class="">
select<br class="">
('avg overhead', 1269.0761219)<br class="">
('avg process', 22017.891367999997)<br class="">
<br class="">
CAF<br class="">
('avg overhead', 1441.6064868)<br class="">
('avg process', 22658.534969599998)<br class="">
<br class="">
_______________________________________________<br class="">
bro-dev mailing list<br class="">
<a href="mailto:bro-dev@bro.org" class="">bro-dev@bro.org</a><br class="">
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
<div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">------<br class="">
<br class="">
Adam J. Slagell<br class="">
Director, Cybersecurity &amp; Networking Division</div>
<div class="">Chief Information Security Officer<br class="">
National Center for&nbsp;Supercomputing Applications<br class="">
University of Illinois at Urbana-Champaign<br class="">
<a href="http://www.slagell.info" class="">www.slagell.info</a><br class="">
<br class="">
&quot;Under the Illinois Freedom of&nbsp;Information Act (FOIA), any&nbsp;written communication to or&nbsp;from University employees&nbsp;regarding University business is&nbsp;a public record and may be&nbsp;subject to public disclosure.&quot;&nbsp;<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
</div>
</div>
</div>
</div>
</div>
<br class="">
</div>
</body>
</html>