Request threading issues?
See original GitHub issueHi Colin, I’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.
If 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.
Msg msg = null;
ConnectionFactory cf = new ConnectionFactory();
var sw = new Stopwatch();
sw.Start();
using (var c = cf.CreateConnection())
{
var tasks = Enumerable.Range(0, 10000).Select(x =>
Task.Factory.StartNew(() =>
{
msg = c.Request("AppointmentSearch", new AppointmentSearch().ToMsg(), 10 * 1000);
})
);
Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(10));
}
return sw.ElapsedMilliseconds;
Looking 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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Python Threading/Request issue
I have a multi-threading code in Python (firing several threads every second and closing them after), and it used to work fine. Recently,...
Read more >What are threading issues
What are threading issues - We can discuss some of the issues to consider in designing multithreaded programs. These issued are as follows ......
Read more >Managed Threading Best Practices
Multithreading requires careful programming. For most tasks, you can reduce complexity by queuing requests for execution by thread pool threads.
Read more >How To Resolve Multi-Threading Problems
Whenever a thread wants to enter a critical region, it requests permission from the semaphore. If the semaphore counter is greater than zero, ......
Read more >An Intro to Threading in Python
In this intermediate-level tutorial, you'll learn how to use threading in your Python programs. You'll see how to create threads, how to coordinate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chrismcv I agree, but think this has more to do with the task scheduler itself, than NATS code. I wrote a few tests using Tasks that failed quickly (running on VM), similar to your results. The tasks weren’t being scheduled in a performant manner, likely due to resources constraints. However, when I moved down to using threads I found the performance I was expecting. 300 threads requesting, with the responder randomly delaying up to 5 seconds, and the tests passed about the same time as the delay, indicating there was little to no contention in request calls. The responses were received were out of order, as expected, also indicating little contention. Each subscription does have its own channel, so they shouldn’t step on each other. This is an interesting problem… That being said, this needs to be addressed and I will continue looking.
I created the following method
and using
I get much better throughput - e.g. 600ms for 10,000. I suspect the
SubscribeSync
inrequest
is blocking otherTasks
butSubscribeAsync
isn’t.