<div dir="ltr">Often processing incoming packets can require exclusive access to scene data structures. I'd avoid using a threadpool task (FireAndForget) to process a incoming packet to avoid potential lock contention and threadpool task exhaustion.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 24, 2014 at 9:30 AM, matt lehmann <span dir="ltr"><<a href="mailto:mlehmann8@hotmail.com" target="_blank">mlehmann8@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">Hello,<br><br>The current implementation of UDP reception ( as of the latest release ) is as follows.<br><br>-- create an async read cycle on the socket, adding packets to a blocking queue<br>-- create a smart thread which waits on the blocking queue, servicing new packets as the occur<br><br>I propose a simpler solution, which will give more control over rate of reception, and also eliminate the need for two separate threads in reception.<br><br>This solution involves polling the udp socket, from within the smart thread.<br><br>The function IncomingPacketHandler, from within the LLUDPServer class changes to this:<br><br>private void IncomingPacketHandler()<br> {<br> <br>....<br> IncomingPacket incomingPacket = null;<br><br> base.pollReceive();<br> while(packetInbox.Count > 0)<br> {<br> incomingPacket = packetInbox.Dequeue();<br><br> ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket);<br><br> if (UsePools)<br> m_incomingPacketPool.ReturnObject(incomingPacket);<br> }<br> <br>....<br>}<br><br>packetInbox is now a standard .NET queue.<br><br><br>The method, pollReceive on the base class looks like this:<br><br> public bool pollReceive()<br> {<br><br> if (m_udpSocket.Poll(100, SelectMode.SelectRead))<br> {<br><br> UDPPacketBuffer buf = new UDPPacketBuffer();<br> buf.DataLength = m_udpSocket.ReceiveFrom(buf.Data,<br> 0,<br> UDPPacketBuffer.BUFFER_SIZE,<br> SocketFlags.None,<br> ref buf.RemoteEndPoint);<br> PacketReceived(buf);<br> return true;<br> }<br> return false;<br> }<br><br><br>This setup should allow for better throughput, as there will be less context switching and reliance on the .NET threading runtime to service the async requests. Also, it would now be possible to throttle incoming packets under heavy loads.<span class="HOEnZb"><font color="#888888"><br><br><br><br><b><u> Matt Lehmann </u></b> </font></span></div></div>
<br>_______________________________________________<br>
Opensim-dev mailing list<br>
<a href="mailto:Opensim-dev@opensimulator.org">Opensim-dev@opensimulator.org</a><br>
<a href="http://opensimulator.org/cgi-bin/mailman/listinfo/opensim-dev" target="_blank">http://opensimulator.org/cgi-bin/mailman/listinfo/opensim-dev</a><br>
<br></blockquote></div><br></div>