{"action":"created","issue":{"url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2108","repository_url":"https://api.github.com/repos/akkadotnet/akka.net","labels_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2108/labels{/name}","comments_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2108/comments","events_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2108/events","html_url":"https://github.com/akkadotnet/akka.net/issues/2108","id":161536438,"number":2108,"title":"100% CPU Utilisation in Akka.IO server.","user":{"login":"Lewis-H","id":1710296,"avatar_url":"https://avatars.githubusercontent.com/u/1710296?v=3","gravatar_id":"","url":"https://api.github.com/users/Lewis-H","html_url":"https://github.com/Lewis-H","followers_url":"https://api.github.com/users/Lewis-H/followers","following_url":"https://api.github.com/users/Lewis-H/following{/other_user}","gists_url":"https://api.github.com/users/Lewis-H/gists{/gist_id}","starred_url":"https://api.github.com/users/Lewis-H/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lewis-H/subscriptions","organizations_url":"https://api.github.com/users/Lewis-H/orgs","repos_url":"https://api.github.com/users/Lewis-H/repos","events_url":"https://api.github.com/users/Lewis-H/events{/privacy}","received_events_url":"https://api.github.com/users/Lewis-H/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/akkadotnet/akka.net/labels/akka-io","name":"akka-io","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-06-21T20:51:36Z","updated_at":"2016-08-31T04:38:18Z","closed_at":null,"body":"I'm new to the code so I hope I'm not missing something here...\r\n\r\nThis issue was [reported before](https://github.com/akkadotnet/akka.net/issues/1225) and closed, but is not fixed. I have 100% CPU usage on one core when running an Akka.IO TCP server. I've looked into the issue and found that the problem is that C# provides no way to interrupt/cancel `Socket.Select()` and Akka.NET is running in a continuous loop because the listening socket (correctly) never leaves the `_read` list.\r\n\r\nHere is the [Scala code](https://github.com/akka/akka/blob/65a9e0a0f9372d2e2ecb945c8a9dae129a438f77/akka-actor/src/main/scala/akka/io/SelectionHandler.scala#L205), vs the [C# code](https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka/IO/SelectionHandler.cs#L201) for `SelectionHandler.Execute()`.\r\n\r\nThe important part is the `selector.wakeUp()` method. In scala, the selector waits forever, until either something happens on any of the sockets or `wakeUp()` is called within `execute()` to make the thread process the action that was pushed to the queue instead.\r\n\r\nIt seems there is no equivalent `wakeUp()` method in C#. One way I can think is to set no timeout (pass -1 to `microSeconds` argument in `Socket.Select()`) and connect an \"interrupt socket\" to the port after binding and, when we wish to exit `Socket.Select()`, send an empty byte array through this \"interrupt socket\". I don't know how this would affect performance, however. It's a hack, and potentially too slow for Akka.\r\n\r\nAnother, perhaps more performant, option is to redesign the socket server so it provides the same functionality without being exactly the same under the hood. Although, perhaps using `SocketAsyncEventArgs`, we can wrap this in a \"Selector\" class that behaves like [java.nio.channels.Selector](https://docs.oracle.com/javase/7/docs/api/java/nio/channels/Selector.html) to keep the code looking similar to the Scala? I'm not sure if this is possible, though, so would need to be looked in to.\r\n\r\nAny thoughts?"},"comment":{"url":"https://api.github.com/repos/akkadotnet/akka.net/issues/comments/243656374","html_url":"https://github.com/akkadotnet/akka.net/issues/2108#issuecomment-243656374","issue_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2108","id":243656374,"user":{"login":"willieferguson","id":1113951,"avatar_url":"https://avatars.githubusercontent.com/u/1113951?v=3","gravatar_id":"","url":"https://api.github.com/users/willieferguson","html_url":"https://github.com/willieferguson","followers_url":"https://api.github.com/users/willieferguson/followers","following_url":"https://api.github.com/users/willieferguson/following{/other_user}","gists_url":"https://api.github.com/users/willieferguson/gists{/gist_id}","starred_url":"https://api.github.com/users/willieferguson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willieferguson/subscriptions","organizations_url":"https://api.github.com/users/willieferguson/orgs","repos_url":"https://api.github.com/users/willieferguson/repos","events_url":"https://api.github.com/users/willieferguson/events{/privacy}","received_events_url":"https://api.github.com/users/willieferguson/received_events","type":"User","site_admin":false},"created_at":"2016-08-31T04:38:18Z","updated_at":"2016-08-31T04:38:18Z","body":"@Horusiath I've looked at the TcpSpec failures and they were cause by a couple of bugs in the spec and Akka IO - see willieferguson/akka.net@cb57f2630030b863cddce287e15b235e63fdeb17. The spec now pass for the current Akka IO design as well as the new one. \r\n\r\nI need to change the UDP connection to the new design and will then push the new design for review. "}}
{"actor":{"display_login":"willieferguson"}}