Large screen technology evolution - push mode

First, the problem

  • In our last article "Large screen technology evolution - pull mode "finally thinking part, we made it a condition single-use pull mode can actually, timing control what time granularity problem, the whole structure is simple, that if we have the conditions to increase it, use that model is not yet back according to the front of simultaneous requests to issue conditions to calculate it?
  • In fact, if we can understand a lot of time in a large amount of log data may not be packed in the big screen above, that we are all human society in general communication: something you call me, all right Do not call me (as little as possible to do so, would no friends ), in the service architecture, let's try to do: I have a log report notification, and the timing of the front end does not need to pull data, the data is pulled consume network traffic.

Second, the solution

So based on the above two issues, we need to think about the direction that the push mode, websocket use here, the central idea is this: there is a large screen there is a network log report request, to be honest did not report it, do not send the request, and forget it

Then the corresponding websocket not understand students can consider a look  WebSocket principles and how to use  , which explain in more detail.


Our timing diagram:


Description:

  1. Big screen when opened, will launch a websocket the connect request, this time the connection is successful, it will be a token of return.
  2. The condition parameters and the returned token distal bind request to submit a request to merge server, the server token with a binding operation conditions, the only condition value calculation, we used a MD5, performed inside a collection redis operating.
  3. Background task periodically to pull this relationship, and the extraction condition parameters out, the condition is a separate process to perform the corresponding calculation, multicore cpu below, may be considered to use a thread or multiple processes is achieved, of course, if a go language , the direct use of the built-in coroutine also possible, after all, to achieve csp model at the language level is still very good.
  4. Since a plurality of data generating modules, and multiple modules Here are some real-time data, some data is to increment, each time data in the previous calculation are covered, and only the incremental determine whether the current data data, no data can not overwrite data source, data can only be overwritten.
  5. It is found after the data has changed version, the server notifies the condition (condition) and the list of modules (modules) need to be updated, the server receives the request, which will be the condition corresponding to the relationship extraction token, then the token to initiate a disposable service-side push operation, content is the list of modules (modules)
  6. After the front-end onmessage response is received, after the module using a token request to obtain data corresponding to the server module, the server to obtain a list of modules which correspond redis extracted data returned directly to the front end.
  7. The process is generally spoken above.


Third, the problems in the process of

Q: websocket Why use ping / pong maintained?

A: Because the program inside, ping / pong heartbeat used to determine whether to open a big-screen, big-screen data to calculate because we are with our conditions to go in the back end, if we dropped the big screen, and can promptly notify background task, then we calculate the amount will be much less

Q: use ping / pong can be a hundred percent sure my websocket not disconnected it?

A: The answer is no, the Internet aiming at hundred percent no matter, a network jitter, our ping / pong is likely to hang up, this situation is normal, we will for the ping / pong on business Some retry mechanism, this may retry a short time, such as that initiated the request within 1s how many times; if the request can not obtain the data is correct, then the server expires, in fact, this token is not much use, and on the front there will be a timer to detect communication with the local websocket service if there are problems, there is no question of re-connect operations, and in the detection process, we have a downgrade, we will become operational websocket traditional pull model, this should be combined with our previous file technical solutions.

Q: I'm sure the conditions will change, the change proved to do?

A: That is a good question, because what switch large screen parameters directly led to many of us is the need to re-render the data module, then we need to re-send push operation, then follow logically consistent.

Q: Why use the token involved in it, I had been logged, and directly uid can not?

A: We started also take into account the uid of the program, why not do it, mainly token we have here is associated with websocket, you can approximate considered socket inside fd, for example, I am a man opened a 10 screen, then I pushed that moment, I need 10 big-screen data can be pushed, but the difference is that, uid only one, token is 10


IV Summary

Why here took two big screen this space to write it, mainly in simple scenario, we would be more suitable version 1.0, after all websocket with respect to the process a little complicated, wrong place at the intermediate node will be a little more, but complex scene below, you must do the design, so we separate the two articles to be explained.

Hope that through two articles, the students were able to learn relevant knowledge large-screen production technology solutions, allows us to respond to product manager End (Diao) United States (drill) demand, we have a very appropriate technical solutions output.




Reproduced in: https: //juejin.im/post/5d05055e6fb9a07ea803c8ad

Guess you like

Origin blog.csdn.net/weixin_33889665/article/details/93168990