Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async instead of sync methods in realtime classes #6777

Conversation

AndrewVoisovych
Copy link

@AndrewVoisovych AndrewVoisovych commented Sep 15, 2023

Changes

I changed all synchronous calls to asynchronous calls in interfaces/classes:

  • IOnlineClientStore
  • IOnlineClientManager / OnlineClientManager
  • OnlineClientManagerExtensions
  • InMemoryOnlineClientStore
  • RedisOnlineClientStore.cs
    And in all places where they are called (including tests).

Removed:

  • SignalRRealTimeNotifier.SendNotifications() method and depends:

I also changed the logic of IOnlineClientManager.GetAllByUserId,
namely optimized this by storing a separate hash set of users with references to the connection hash set in Redis.
Added GetAllByUserId / GetAllByUserIdAsync to IOnlineClientStore and RedisOnlineClientStore.

Reasoning

When using the latest version of a project, I noticed that the number of threads in the thread pool grows about x3 times the usual value since synchronous calls create thread pool starvation issues.

First, you can see the graphs from Application Insights, which clearly show the increase in ThreadPool:

general chart

chart with max thread count

The following screenshots are an accurate description of what blocks the application the most, and it turned out to be synchronous methods:

blocked time functions

blocked time functions 2

This all means that synchronous calls block and should be replaced with asynchronous calls

About Redis
In the current implementation, all online clients are retrieved from the Redis cache, which is very expensive. For instance in production env, this means transferring ~3 MB of data.

After local changes and testing, the situation has improved, so I would like to see these changes in the framework itself.

@AndrewVoisovych
Copy link
Author

@dotnet-policy-service agree

@ismcagdas
Copy link
Member

@AndrewVoisovych thank you very much for your contribution.

@ismcagdas ismcagdas added this to the v9.0 milestone Sep 18, 2023
@ismcagdas ismcagdas self-requested a review September 18, 2023 06:34
@ismcagdas ismcagdas merged commit 3fb1a74 into aspnetboilerplate:dev Nov 9, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants