Background
The distributed lock service may not be used much in everyone's project, because everyone put the exclusive on the database layer to block. When a large number of row locks, table locks, transactions filled with the database, it is better to change the angle of thinking. General Web applications A lot of bottlenecks are in the database, here to introduce you to reduce the database lock burden of a scheme.
Brief introduction
If our requirements are simple, for example, for the user's account funds, to ensure that the atomic operation. and different clients can commit only one object operation at the same time. Lock, single case?! On a single platform can also, but on large Web projects, load balancing is a commonly used technical means, the same meaning objects may have different replicas, then how we guarantee exclusive operations. The transaction of the database! In addition to this, we then draw the topic of this chapter, the Distributed lock service.
A simple lock service is not difficult to implement, and even using memcache can quickly construct a distributed locking system. We only need to be in the operation of the object to write the KV key value pairs, the operation is completed when the release of KV, in the reading of the object to determine whether there is data in kv, we can even give it a default release time.
It's a solution, but if we're asking a little bit higher, we need permission to authenticate (such as only requests from the XXX domain name), the need for a subordinate node association (for example, a user's fund account is locked, while locking his cart, points, etc.), the need for monitor callback, and even consider a single point of failure. So, Bugs here recommend another set of options----zookeeper.
Zookeeper
Official documents: Http://zookeeper.apache.org/doc/r3.3.2/zookeeperOver.html#ch_DesignOverview
Download: http://zookeeper.apache.org/releases.html
Zookeeper is a module in Hadoop. is a distributed, open source distributed Application Coordination service that can be used to synchronize services and configure maintenance.
More content to see the document or directly online search, theoretical content written more people sleepy. We look directly at practice.
Performance Chapter
Server Ubuntu (virtual machine one)
Client window2003
The service side installs the Java environment and follows the official introduction deployment
Start Zkserver
We test the lower lock service-related operations
This article URL address: http://www.bianceng.cn/Programming/csharp/201410/45479.htm