E
E
Erix Rolex2017-10-13 21:16:59
Redis
Erix Rolex, 2017-10-13 21:16:59

Where is it better to store the socket connection with each client, in a regular array or in redis?

And why.
Radishes is fast, but is it faster for these purposes than regular array variables?
Variables are also stored in RAM.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaliy2, 2017-10-15
@Erixx

Obviously, radishes are much slower than normal variable access, so it's best to store everything in variables. Sending requests will give a particularly large overhead. For example, 100-200 thousand simple requests per second, they may well load your script by 100% and redis by 30 percent.
Nevertheless, redis is still a very useful thing for the following reasons:

  1. It is convenient to store persistent data that should not be lost after stopping/restarting the script or the server.
  2. If access to data is required from several scripts at once. In this case, if you use storage in ordinary variables instead of radish, you will get the following problems:
    • Data will have to be duplicated in several scripts at once, which can significantly increase memory consumption
    • You need to make sure that all scripts contain the current version of the data.
    • This greatly complicates the project and its support. If earlier, in order to change something, it was enough for us to write it to the database from any script, now we have to interact with each of these scripts. Moreover, simply interacting will not work, you also need to add code to the scripts themselves that will respond to this interaction and update the data in its memory, and also, possibly, interact with other scripts.
      In general, as you can see, in order to perform even such a simple operation, you have to do a huge number of actions, but before with radishes, we just needed new data in the database and that's it.
      Another example is code becoming dependent. Previously, we did not store anything in the script's memory and all requests were completely isolated from each other. Now they depend on some global data stored in the script's memory. Firstly, request handlers become tied to each other, secondly, the state of each such subroutine becomes more complicated, since now there is a dependence on global data, and thirdly, they can no longer be so easily taken and moved to another place.

As a result, both storage options are good, just each option should be used in its own situation. We also allow the third option - storage in radish with caching in the script's memory.
Of course, it is better to store sockets in the script memory, because they do not require constant storage even after the server is restarted and are not needed in other scripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question