Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of concurrency optimization of transfer services?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the method of concurrency optimization of transfer services". In daily operations, I believe that many people have doubts about the methods of concurrency optimization of transfer services. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of concurrency optimization of transfer services?" Next, please follow the editor to study!

I. background

The business reports that the Transfer service of Java has a call timeout.

II. Problem troubleshooting and optimization

Read the code to find that after the data comes, the loop processing, messages on the local queue, is the way of synchronization, where concurrency will certainly affect performance, decisive optimization

Third, the optimization process IV, experience summary 1, minimize IO operations

In particular, network IO, especially the use of network IO in for loops, if necessary, consider using caching instead.

Case 1: when you call hbs to obtain uuid, you can actually get it from DB, and only if you cannot get it, you can get it from the API. This call API problem is also the main reason for the slow service. If the size of list is 1000 and does not have uuid for each request, then you have to access the API 1000 times. How fast?

Case 2: data will be delivered to kafka in the loop, which is also network IO, which may be much faster than calling hbs, but it is still network IO, which still affects performance, so it is changed to local IO and ConcurrentLinkedQueue based on optimistic lock is used later.

2. Asynchronous processing

If the business does not care about the service response content, consider modifying the interface to be asynchronous, so that the business request is returned immediately, and the server needs to consider how to deal with the service quickly.

For example, after asynchronism, the problem of client waiting can at least be solved to avoid affecting the client due to server problems.

3. NIO concept, segmented processing, reducing waiting

First, let's talk about the logic after optimization (processed in four segments). Each segment has a thread pool, and each thread pool has a different name, which is easy to observe:

-- "receive requests, multithreaded asynchronous processing

-- "when adding data to ConcurrentLinkedQueue in a loop, use multithreaded asynchronism (although optimistic locks, but will also encounter spin conditions)

-- "add a scheduled task to consume ConcurrentLinkedQueue data once a second, and put the data into list

-- "Multithreading, when list reaches 200, push to kafka

Then add monitoring to the buffer queue of each segment of the thread pool to observe which step has a backlog, indicating that that step may be slow and can appropriately increase the number of threads.

4. Rational use of third-party cache and local cache

Local cach

Advantages: high speed, no need to establish remote connection, network transmission process and other consumption

Disadvantages: occupy local memory, when the system processing speed is slow, resulting in a backlog of local data, thus consuming local memory, resulting in frequent GC

Third-party cache

Advantages: do not occupy local cache

Disadvantages: slow speed, need to go through the establishment of remote connections, network transmission process and other consumption

The system collects two ways: use local ConcurrentLinkedQueue to store offer data, use kafka to buffer when consuming ConcurrentLinkedQueue data is delivered to the platform server, and use flink to consume kafka data to be sent to the platform server.

Why would you do that?

1. Local ConcurrentLinkedQueue storage is used when offer data is stored, mainly considering that this kind of data is consumed quickly and will not cause local backlog.

2. Delivery to the platform service, because the http connection is to be established, it may be affected by the stability of this service, so in order to ensure the stability of this service, use flink to do this.

5. Separate compute-intensive services from IO-intensive services

Apply for relevant configuration consultation reasonably to improve the concurrency ability.

This service has both operations. For example, loop traversal is computationally intensive.

Pushing data to the remote end is network IO-intensive, so it is easy to wait if you put it into a service, especially a thread logic, so it needs to be separated here, and then for computing-intensive, apply for cpu with good performance, and for IO-intensive choice of disk or network card.

How to estimate the concurrency bottleneck of the computer?

For a 2GHZ CPU, the transport speed is 2 billion times per second, which means that if it is a pure CPU-intensive operation, it can theoretically reach 2 billion concurrency for simple requests, of course, this is impossible, because network requests are also affected by many factors, such as thread switching consumption, network IO overhead, connection establishment process, and so on, which are only for evaluation.

At this point, the study on "what is the method of concurrency optimization of transfer services" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report