Reduce network latency and memory access

Tram Ho

Network latency

How to optimize network latency (we are looking at client-server model):

  • Use persistent connection.
  • Reduce the amount of data transmitted over the network

Use persistent connection


Reference images on the internet

In the illustration above, we see that with a non-persistent node connection it will take more time due to having to re-establish the connection. So we should choose persistent connection for network protocols.

What network protocol are we using our system?

  • Http1.0 uses non-persistent connections;
  • Http1.1, Http2.0 and Http/3 use persistent connections;

Should choose Http2.0 or Http/3 because it gives faster loading speed than Http1.0 and Http1.1

  • If the server communicates with the server, we should use Http2.0 (usually gRPC) or use Message broken (eg RabbitMQ uses AMQP protocol).

Reduce the amount of data transmitted over the network

  • We use browser-side caching technique to cache the script files, json, … to speed up the following visits;
  • We need to Bundling and Minification of script files before sending to client;
  • Compress data before sending it over the network.

Reduced latency of memory access

We need to do the following:

  • Avoid memory bloat
    • Keep the code base as small as possible. Because when running the program, the code base is also loaded into memory. However, our application depends on the framework so it is difficult for us to control the size of the code base. But here I have some suggestions to do well in architectural design and code according to the design pattern (if you are using object-oriented).
    • We avoid declaring objects unnecessarily to avoid head memory bloat.
    • Make good use of the dispose pattern, to destroy resources when not in use.
    • Avoid using libraries that consume a lot of memory, for example, when processing excel, close xml consumes more memory than aspose .
  • Use Weak References for Large Objects
  • Break up a large process into many small processes.
  • For the database, it is necessary to normalize (normalize) so that the query is more optimized, because there are fewer joins, so the memory used under the database is also less.
Share the news now

Source : Viblo