618 battle, victory double eleven high spike concurrent decryption system - rear java programmer LiJian

EDITORIAL

2011 618 Jingdong event can be seen, high-concurrency server pressure is still very large, Jingdong last 618 finally be resolved by extending the event, but Suning planning seems not learn from the experience of the accident, the same problem occurred, remember correctly, taobao also had the same thing happen, 12306 tickets can also be Masi ,, so in planning programs to fully consider how to do plan these special circumstances ...

image

This article details attached video, you need to be collected at the end of the article!

Business Analysis spike

image

Those scenes belong to spike business?

  1. Commodity buying
  2. Red group
  3. Coupon receive
  4. Grab tickets
  5. online reservation
  6. ……

The story tadpoles running race starting line of

image

image

Those things on lock

Pessimistic locking resolve

For the pessimistic locking concept There are two main explanation, but essentially pessimistic concurrency control locks mainly for database access.

  • One explanation

Pessimistic lock refers to data is modified outside world (including other current affairs of the systems, and transaction processing from external systems) conservative, and therefore, the entire data processing, the data is locked, the situation in pessimistic locking next, in order to guarantee transaction isolation, we need consistency locked read. To lock when reading data, other transactions can not modify these data. Also locked when modified to delete the data, other transactions can not read the data.

  • Interpretation II

In a relational database management system, pessimistic concurrency control (also known as "pessimistic locking", Pessimistic Concurrency Control, the abbreviation "PCC") is a method of concurrency control. It can prevent a transaction to affect other users of ways to modify the data. If the operation is performed in a transaction are applied to the data lock a row, and that only when the transaction lock release, other transactions will be able to perform operations with the lock conflict.

Pessimistic locking process flow

  1. Before any of the records to be modified, first try for the record plus exclusive lock (exclusive locking)
  2. If the lock fails, indicating that the record is being modified, then the current query may have to wait or throw an exception
  3. If successful lock, then you can make changes to the record, after the transaction is completed will unlock
  4. If there are other modifications made during the record or add exclusive lock operation will be waiting for us to unlock or direct throw an exception

Pessimistic locking advantages

  • Pessimistic concurrency control is actually a "lock and then take the first visit," the conservative strategy, to provide a guarantee for the security of data processing.
  • DB level achieved based on pessimistic locking, no invasion of the business code, easy to use

Pessimistic locking shortcomings

  • Pessimistic lock suitable for reliable persistent connection, such as C / S applications. For HTTP connection Web applications, congenital NA
  • Use means that the performance of the lock loss at high concurrency, locking the long duration of the case, particularly serious. Web application performance bottlenecks more at the database, use pessimistic locking, and further tightened the bottleneck
  • Unlocking mechanism under abnormal circumstances suspend, design and implement a lot of trouble, the cost is still high
  • Under less than rigorous design, could produce deadlock inexplicable, it can not easily be found
  • Pessimistic flaw is whether page locks or row locks, lock time can be very long, so long may restrict access of other users, that is to say pessimistic locking concurrent access of the poor

Optimistic locking resolve

In a relational database management system, the optimistic concurrency control (also known as "optimistic locking", Optimistic Concurrency Control, the abbreviation "OCC") is a method of concurrency control. It is assumed multi-user concurrent transactions do not affect each other during processing, each portion of the data processing transactions to their influence is not generated in the case of the lock. Prior to submission of data updates, each transaction will first check after reading the data of the transaction, there is no other transaction has modified the data. If other transactions have updated, the transaction is submitted will be rolled back. Optimistic transaction control was first proposed by Professor H. T. Kung (HTKung).

With respect to the pessimistic locking, when the database processing, and will not use optimistic locking lock mechanism provided by the database. General implementation optimistic locking way is to record data release

Advantages and disadvantages

Optimistic concurrency control believe that the probability of data races (data race) between the transaction is relatively small, so as to make direct it, until such time as submitted only to lock, so it will not have any locks and deadlocks. But if straightforward to do so, or may encounter unexpected results, such as two transactions were read a row of the database, through modified later written to the database, then you have a problem.

Optimistic locking implementation process

Three operations ensure atomicity

image

image

Spike combat core services

Hands implement core services

  • Achieved by version number based mysql;
  • Based MySQL via a state;
  • Based cas mechanism of memcached;

Cache implementation optimistic locking scheme

image

Further thought

  1. CAS mechanism will be able to solve the problem spike?
  2. Architect's eyes, the whole picture spike system?

This article is over! Like little like a friend and look! thank! Another of the attached video to explain in detail the complete, need friends can click on the following link for!

Java learning, interviews; documentation, free access to video resources

Guess you like

Origin blog.csdn.net/qwe123147369/article/details/91867400