Z
Z
zanooda2015-11-26 23:54:08
ASP.NET
zanooda, 2015-11-26 23:54:08

How to minimize server load for chat on ASP.NET MVC with SignalR?

There is a game chat on ASP.NET MVC using SignalR. There is a database with dialogs, replicas and users (AspNet.Identity). There are four controllers (BaseController which is inherited from Controller and in which the context of dialogs and replicas is created, the standard AccountController which is inherited from BaseController, HomeController which is inherited from BaseController and VerseController which is also inherited from BaseController) and a signaler hub in which you also need to create a database instance that to write new replicas into it without reloading the page.
If I'm not mistaken (and I can, easily), then every time the user opens the site, a controller instance is created on the server in which a context is created and a function is launched that processes the context and displays it in the View. That is, if a thousand users use the chat at the same time, then a database instance is created on the server a thousand times. I would like that while using the chat on the instance server, the database was created only once. Where is the question? WCF? Web API? Only in SignalR hub? What is the best way to do this in order to minimize the load on the server and make the chat work quickly and without delays for a large number of users?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dasha Tsiklauri, 2015-11-27
@zanooda

Not a context instance, but not the database itself - different things!
Use dependencyInjection and reuse the db context instance in every subsequent controller, NInject will do.
Where is the server hosted? IIS? Katana? If IIS, then it is worth remembering that the pool can be killed, respectively, the objects are not eternal, unlike self-hosted.
In order to minimize the load and not get tied to the database, it is worth thinking over the cache in RAM, thinking over scenarios for refreshing the page and loading the recent history. And, of course, it is correct to use an entity for reading (Do not track everything) and writing (insert in batches - bulkinsert on a timer, if you need a lot of inserts).

E
eRKa, 2015-12-04
@kttotto

I have exactly the same question for the second week, only in a different context. Monitoring of GPS trackers. There is a server part that receives a message from the tracker via the UDP protocol and which also has access to the database to understand who owns the tracker, then the message goes to the SignalR hub to be sent to the web client. It turns out that I have two connections to the database, from the server with the site (ASP.NET MVC) and from the server with the hub. And I also think about how to make one connection so that the base is less strained, and I also spin around WCF or Web API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question