<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:verdana,helvetica,sans-serif;font-size:10pt">I am using Intel VTune profiler and the hits ~20% was in the function enet_protocol_dispatch_incoming_commands.<br><div>I think the reason why enet is taking much of the processing time because first<br><br>1) it receives the packet from up to 5 clients (which send @60hz, and each of them is about 1kb-2kb, so each second it receives up to 120kb per client). The packet size received is just my estimation but I tried not to exceed the MTU max size.<br><br>2) and then it will retransmit some of the packets back to all clients.<br><br>I have a dateline this tuesday to have stable server and to have a stable one, the most crucial thing is to have server running the physics @60hz. I think without mult-threading, it is not possible. Anyway, I will post my findings once the code is working.<br><br>I think this
 could be interesting as CPU dice scales up (quad-core, eight-core etc) and I dont think multi-threading enet is that difficult as the enet can keep most of the data to iself (hence, the thread it is running on).<br><div style="font-family: verdana,helvetica,sans-serif; font-size: 10pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Blair Holloway &lt;thynameisblair@chaosandcode.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> Discussion of the ENet library &lt;enet-discuss@cubik.org&gt;<br><b><span style="font-weight: bold;">Sent:</span></b> Fri, February 5, 2010 6:39:40 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [ENet-discuss] Multi-threading ENet the easy way...<br></font><br>
<div>The last game I worked on handled 16 players, fully connected (so each machine had 15 active connections), and I think in heated dogfights we peaked around 200 outbound packets per second. I'm reasonably sure enet_host_service wasn't taking 20% of our frame time, or my lead would have whacked me over the head with a cricket bat. :)</div>
<div><br></div><div>I'd be curious to see a more detailed profiling here - do you know where Enet is spending its time?</div><div><br></div><div>Regards,</div><div><br></div><div>- Blair</div><div><br><div class="gmail_quote">
On Fri, Feb 5, 2010 at 1:04 AM, Syed Setia Pernama <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:syedhs@yahoo.com" target="_blank" href="mailto:syedhs@yahoo.com">syedhs@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I have profiled my server which use enet and found that many enet functions are using quite substantial of cpu processing (~20%). I know probably many of you don't see enet as the bottleneck while profiling, but mine is a little different, it is a server which can send (and receive) 60 packets/second to 5 clients. I know, i know that there are some past postings suggested that this is not the best way to do it (60hz), but as it is now it is running okay. But the more pressing issue now is to increase the performance so we decide to make full use of quad core via multi-threading technique.<br>

<br>
What I am thinking of the easy way to multi-thread enet is to specifically run this:-<br>
<br>
std::vector&lt;std::pair&lt;ENetPacket*,ENetPeer*&gt;packets;<br>
while (enet_host_service (mHost, &amp; event, 0) &gt; 0) {<br>
 &nbsp; ...<br>
 &nbsp; switch (event.type) {<br>
 &nbsp; &nbsp; case ENET_EVENT_TYPE_RECEIVE:<br>
 &nbsp; &nbsp; &nbsp; packets.push_back(std::make_pair(event.packet, event.peer));<br>
 &nbsp;....<br>
}<br>
<br>
on thread. The thread will be continuously run 'enet_host_service' function until the server shutdown.<br>
<br>
And the enet packet which is stored using 'packets' variable above, will be made available to main thread via another function -<br>
<br>
void getPackets(std::vector&lt;std::pair&lt;ENetPacket*,ENetPeer*&gt;&gt;&amp; packets)<br>
<br>
Of course, this function will perform the necessary lock for multithreading so as to prevent the thread from inserting while main thread is reading it.<br>
<br>
And that's it. The sending part will be in the main thread. The network thread only concern about receiving packets.<br>
<br>
So the big question is, is the design okay?<br>
<br>
TIA.<br>
<br>
<br>
<br>
_______________________________________________<br>
ENet-discuss mailing list<br>
<a rel="nofollow" ymailto="mailto:ENet-discuss@cubik.org" target="_blank" href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br><span>
<a target="_blank" href="http://lists.cubik.org/mailman/listinfo/enet-discuss">http://lists.cubik.org/mailman/listinfo/enet-discuss</a></span><br>
</blockquote></div><br></div>
</div></div></div>
<!-- cg32.c2.mail.re1.yahoo.com compressed/chunked Fri Feb  5 08:04:12 UTC 2010 -->
</div><br>

      </body></html>