Delays and high concurrent cause is not "power, etc." scene and Solutions

Delay "is not a power of other" problems caused

Scene Description:

       A user orders a commodity, for various reasons, in a relatively short period of time, many times a user clicks a single button, if the mobile terminal does not prevent this from happening, it will produce the same request multiple ( + same same request interface request parameters), if the service will be handled properly possible to produce a plurality of orders, so that the dirty data generation may lead to abnormalities other functionality applications and services (not risk assessment).

Scene analysis:

        A reasonable single step includes three steps: Commodity Select -> Submit purchase (generates unique order flow numbers) -> confirm the purchase

        Step two:

                Generate a random order unique serial numbers associated with the user information + product information, the serial numbers as trading interest identifier, the user can continue to trade or abandon the transaction, and can be traced back to the water users of the transaction

        Step three:

                Users submit transactions intent to identify, complete commodity trading.

        Step two is essential, only the "User Information + product information" can not determine the user that the transaction operation (commodity should not have uniqueness) as a unique identifier.

solution:

        In the case of the same high concurrent requests (a very short time, the same request to initiate multiple times)

                You can add granularity is "uniquely identifies the user," or "unique order flow numbers" lock guarantee the same time, only one process accesses;

        For the case of network delay (the same request to initiate multiple times, to reach the service requested two consecutive time intervals longer [ `` locking effect caused])

                1, the order flow numbers as a unique key, when the data into the database, success will continue the rest of the business process; fails to give up the rest of the business processes.

                2, the write operation is performed before the first check the state of records in the database, and then decide whether to continue the remaining process.

                3, upload parameters include token, token use is one-time, when the token with the current session state held token credentials must be consistent only after the process to continue, but after the end of the process, the session held token is either deleted or updated.

        At least two networks need to be considered when developing situation! (That is what I thought)

 

High concurrency "no power and other" problems caused

Scene Description:

        In the mall trading system, there is a "second shot goods" feature, unpredictable user may be limited to buying goods, due to the process of selling commodities, commodities as a critical resource contention multiple processes, if not prevent, It may cause actual number of users to buy goods than goods.

 

Scene analysis :

        1, the same request to initiate multiple reject (limiting by the client).

        2, create a queue of goods "to be snapped up."

        3, access to critical resource identifier (when pop [atomic] take time to value, believe that the success gained critical resources, or do not think to get critical resources, reduce the use of locks to avoid network problems caused because of the complexity and plus unlock caused by the complexity of business processes) decided to continue the process after

 

solution:

        A complete flow of goods buying activity should be so:

                The article is ready (ready queue) -> activities (consumer queue) -> end of the event (monitoring queue)

 

Published 31 original articles · won praise 3 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_36557960/article/details/100717963