Skip to content

Commit

Permalink
akka-io: fixed #1225 - High CPU load using the Akka.IO TCP server
Browse files Browse the repository at this point in the history
  • Loading branch information
fergusn committed Aug 11, 2015
1 parent d20f17f commit 4af2cfb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/Akka/IO/SelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void Select()
var writeable = _write.Keys.ToList();
try
{
Socket.Select(readable, writeable, null, 0);
Socket.Select(readable, writeable, null, 1);
foreach (var socket in readable)
{
var channel = _read[socket];
Expand Down

4 comments on commit 4af2cfb

@evertmulder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a fix for issue #1225. This code is wrapped in a if statement:
if (_read.Count > 0 || _write.Count > 0)
Both a counts are 0, causing the select to be called over and over again in a tight loop.

@chris-ray
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should poll be used in addition to select? Or perhaps thread sleep for 1ms if read and write count are both 0? I don't know the implications of this method so these are just shot-in-the-dark suggestions

@evertmulder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is polling even needed? Why do not use something like:

listener = new System.Net.Sockets.TcpListener(IPAddress.Any, settings.Port);
 var acceptClientTask = Task.Factory.FromAsync<TcpClient>(listener.BeginAcceptTcpClient, listener.EndAcceptTcpClient, null);

@fergusn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Akka.NET IO is currently a straight port from Akka JVM, which uses selectors. It will require design changes to switch to async IO. I have done some initial work on this and we might include in some time in the future.

Please sign in to comment.