In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Scene introduction
Many Internet scenarios (such as commodity instant kill, forum reply building, etc.) need to be locked in order to control the sequential access of certain resources. If the application service cluster is deployed, it involves locking the distributed application. At present, there are three main ways of distributed locking: (disk) database, cache database and Zookeeper. Next, let's take a look at the locking practice.
Locking implementation
Test code
Suppose 20 threads snap up 10 mate10 phones:
Running result
Configure the actual cache instance connection address, port and connection password, run the code, and get the following results:
Unlocked scene
If the locking code is commented out and there is no lock, the purchase is out of order.
The result of running after commenting the locked code shows that the processing is out of order:
In general, using cached instances of type Redis in DCS services to implement distributed locking has several advantages:
1. The lock operation is simple, and the lock can be acquired and released by using several simple commands such as SET, GET, DEL and so on.
2. The performance is superior, and the read and write of cache data is better than that of disk database and Zookeeper.
3. High reliability. DCS has master / slave and cluster instance types to avoid single point of failure.
The above code implementation only shows the convenience of locking access using DCS services. Deadlocks and lock checking need to be considered in the specific technical implementation. Please click the distributed cache service DCS to learn more.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.