{"action":"created","issue":{"url":"https://api.github.com/repos/nats-io/csnats/issues/55","repository_url":"https://api.github.com/repos/nats-io/csnats","labels_url":"https://api.github.com/repos/nats-io/csnats/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/nats-io/csnats/issues/55/comments","events_url":"https://api.github.com/repos/nats-io/csnats/issues/55/events","html_url":"https://github.com/nats-io/csnats/issues/55","id":149771429,"number":55,"title":"Request threading issues?","user":{"login":"chrismcv","id":145466,"avatar_url":"https://avatars.githubusercontent.com/u/145466?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismcv","html_url":"https://github.com/chrismcv","followers_url":"https://api.github.com/users/chrismcv/followers","following_url":"https://api.github.com/users/chrismcv/following{/other_user}","gists_url":"https://api.github.com/users/chrismcv/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismcv/subscriptions","organizations_url":"https://api.github.com/users/chrismcv/orgs","repos_url":"https://api.github.com/users/chrismcv/repos","events_url":"https://api.github.com/users/chrismcv/events{/privacy}","received_events_url":"https://api.github.com/users/chrismcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-04-20T13:43:22Z","updated_at":"2016-04-21T23:07:53Z","closed_at":null,"body":"Hi Colin, \r\nI'm doing some fairly basic tests at the moment to explore throughput.  I've a system that I want to Request about 20 sources and aggregate the results.\r\n\r\nIf I just use publish (using the same approach as below), then I can comfortably publish 10,000 messages in <300ms on my PC.  So I put together the following snippet with Request, and I was expecting something similar, but am seeing `NATSTimeoutException` instead.\r\n\r\n```\r\n                Msg msg = null;\r\n                ConnectionFactory cf = new ConnectionFactory();\r\n                var sw = new Stopwatch();\r\n                sw.Start();\r\n                using (var c = cf.CreateConnection())\r\n                {\r\n                    var tasks = Enumerable.Range(0, 10000).Select(x =>\r\n                         Task.Factory.StartNew(() =>\r\n                         {\r\n                           msg = c.Request(\"AppointmentSearch\", new AppointmentSearch().ToMsg(), 10 * 1000);\r\n                         })\r\n                    );\r\n                    Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(10));\r\n                }\r\n                return sw.ElapsedMilliseconds;\r\n```\r\n\r\nLooking at `gnatsd -V` I can see a throughput of about 1 message per second.  This doesn't seem right to me?  Is there anything I can look at?\r\n"},"comment":{"url":"https://api.github.com/repos/nats-io/csnats/issues/comments/213153424","html_url":"https://github.com/nats-io/csnats/issues/55#issuecomment-213153424","issue_url":"https://api.github.com/repos/nats-io/csnats/issues/55","id":213153424,"user":{"login":"ColinSullivan1","id":11180189,"avatar_url":"https://avatars.githubusercontent.com/u/11180189?v=3","gravatar_id":"","url":"https://api.github.com/users/ColinSullivan1","html_url":"https://github.com/ColinSullivan1","followers_url":"https://api.github.com/users/ColinSullivan1/followers","following_url":"https://api.github.com/users/ColinSullivan1/following{/other_user}","gists_url":"https://api.github.com/users/ColinSullivan1/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinSullivan1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinSullivan1/subscriptions","organizations_url":"https://api.github.com/users/ColinSullivan1/orgs","repos_url":"https://api.github.com/users/ColinSullivan1/repos","events_url":"https://api.github.com/users/ColinSullivan1/events{/privacy}","received_events_url":"https://api.github.com/users/ColinSullivan1/received_events","type":"User","site_admin":false},"created_at":"2016-04-21T23:07:53Z","updated_at":"2016-04-21T23:07:53Z","body":"@chrismcv - I've added a few tests to illustrate the issue...\r\n\r\nhttps://github.com/nats-io/csnats/blob/master/NATSUnitTests/UnitTestBasic.cs#L510\r\nhttps://github.com/nats-io/csnats/blob/master/NATSUnitTests/UnitTestBasic.cs#L580\r\n\r\nI'm finding that regardless of what is done internally in the NATS client (e.g. changing Tasks into Threads, blocking requests at a higher level using the `Monitor` API), I still run into the limitation and find Threads perform better than Tasks, as one would expect.  The good news is that with these tests, I'm very confident the `Connection.Request` API is sound with respect to thread safety. \r\n\r\nOn the side, I found `TestRequestSafetyWithTasks` succeeded much more often by simply changing the subscriber's message delegate to create a thread rather than a task.  I'm thinking that at some point the task scheduler gets backed up delaying the NATS response.  \r\n\r\nRegardless, your code is much more Task friendly using newer features (await).  We're still adhering to .NET 4.0 code compatibility.\r\n\r\nIs this issue blocking you?   I'm wondering if we should chalk this up to scarcity of resources for the moment, but I can look deeper right now into this this is critical for you."}}