[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 90% probability for extra loop in copas.send(), copas.sendto()
- From: "Soni L." <fakedme@...>
- Date: Mon, 12 Jan 2015 14:47:35 -0200
On 12/01/15 02:43 PM, Oliver Kroth wrote:
Hi,
I am puzzled about a few lines of code in the Copas library functions
copas.send() and copas.sendto():
if (math.random(100) > 90) then
_writing_log[client] = gettime()
coroutine.yield(client, _writing)
end
I believe that is 10%...?
This takes care that send() will give other coroutines a chance to
run, which is good as otherwise one coroutine may send all the time
and no other can be resumed.
E.g. you have a web server where one coroutine sends a download, while
other coroutines wait for incoming connections; these would be blocked
until the download is finished.
But why is this behaviour coupled to a probabilistic value?
--
Oliver
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.