You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by quytrieu37 March 29, 2024
I'm currently using one HubConnection to execute multiple tasks on a hub. I've configured MaximumParallelInvocationsPerClient = 4 in the hub settings. It seems that when tasks complete quickly, they run concurrently. However, if there is a long-running task, it blocks other tasks from running.
To investigate this issue, I logged the thread IDs and found that all tasks from one connection use the same thread. Therefore, when a long-running task occurs, it blocks other tasks.
I utilized Thread.Sleep to simulate a long-running task.
As observed in the provided screenshot, all tasks are executed on the same thread. Consequently, when a long-running task occurs, it causes other tasks to be blocked.
To address this issue, I used Task.Run to execute my long-running task in the background, and everything worked fine.
However, I'm wondering if there is a configuration option to run concurrent tasks from one connection in multiple threads?
And Is the MaximumParallelInvocationsPerClient only allow each client call multiple hub method at same time but in the same thread?
Thank you!
The text was updated successfully, but these errors were encountered:
However, I'm wondering if there is a configuration option to run concurrent tasks from one connection in multiple threads?
No, you can do this by calling Task.Run inside your method or await Task.Yield();. It would be needlessly expensive to do this for every one.
And Is the MaximumParallelInvocationsPerClient only allow each client call multiple hub method at same time but in the same thread?
No. You are blocking the thread by calling Task.Sleep or by running a long synchronous operation. As soon as you go async via Task.Yield or fire a new task and exit the method via Task.Run then you unblock SignalR and allow it to call more methods on the same client.
Discussed in #54835
Originally posted by quytrieu37 March 29, 2024
I'm currently using one HubConnection to execute multiple tasks on a hub. I've configured MaximumParallelInvocationsPerClient = 4 in the hub settings. It seems that when tasks complete quickly, they run concurrently. However, if there is a long-running task, it blocks other tasks from running.
To investigate this issue, I logged the thread IDs and found that all tasks from one connection use the same thread. Therefore, when a long-running task occurs, it blocks other tasks.
I utilized Thread.Sleep to simulate a long-running task.
As observed in the provided screenshot, all tasks are executed on the same thread. Consequently, when a long-running task occurs, it causes other tasks to be blocked.
To address this issue, I used Task.Run to execute my long-running task in the background, and everything worked fine.
However, I'm wondering if there is a configuration option to run concurrent tasks from one connection in multiple threads?
And Is the MaximumParallelInvocationsPerClient only allow each client call multiple hub method at same time but in the same thread?
Thank you!
The text was updated successfully, but these errors were encountered: