Handling of large amounts of expired orders

Source: Internet
Author: User
Tags rabbitmq
    1. Describe your problem
      Recently development encountered a large number of orders expired processing problems, such as I took a product, half an hour after he could not pay or the order should be deleted.

First, the reaction is crontab, but considering every time to check MySQL, feeling will affect the efficiency;
Second, I was prompted to use the message queue RABBITMQ, but I saw a half-day feeling that the message queue seems to be useless, I feel logic or when the order is taken to send a message, and then the PHP process has been in that sleep? It is estimated that I do not understand enough to ask God to explain the relevant process.
Thirdly, is there any other way? The great God gives a specific point of the plan to scatter ~

    1. Paste the relevant code

    2. Post error message

    3. Paste the relevant

    4. What methods have been tried still unresolved (attached link)

Reply content:

    1. Describe your problem
      Recently development encountered a large number of orders expired processing problems, such as I took a product, half an hour after he could not pay or the order should be deleted.

First, the reaction is crontab, but considering every time to check MySQL, feeling will affect the efficiency;
Second, I was prompted to use the message queue RABBITMQ, but I saw a half-day feeling that the message queue seems to be useless, I feel logic or when the order is taken to send a message, and then the PHP process has been in that sleep? It is estimated that I do not understand enough to ask God to explain the relevant process.
Thirdly, is there any other way? The great God gives a specific point of the plan to scatter ~

    1. Paste the relevant code

    2. Post error message

    3. Paste the relevant

    4. What methods have been tried still unresolved (attached link)

Low cost solution

Insert an expiration time when inserting an order

And then the server is constantly querying the MySQL database with CLI mode.

Indexing MySQL expiration time does not affect efficiency

If there is a need for operational costs, it can be achieved through user-triggered mode:

    1. Set the "Expiration Time" datetime when the product is finished.

    2. The user updates the "Expiration Time" at the same time for any updates to the item.

    3. Each time the user logs in, read the relevant products by PHP compared to the current time (if the time is strict, it is recommended to use JS comparison time) and the product expiration time. If it expires, you can use CSS to identify that the current product has expired. The colleague sends the request to the RABBITMQ queue because the product ID has been obtained when the product is read, so the best queue information is to include this ID.

    4. The background has crontab timed to read rabbitmq and batch deleted MySQL statements based on a known ID.

This processing method can save resources, reduce unnecessary consumption of services, basically is a read, a delete database operations. It is not recommended to delete the article by item, it is also recommended to search MySQL to find outdated entries, preferably according to RABBITMQ queue production batch DELETE statements.

You can put an order in Redis to set the expiration time for Redis

The Expiration time index, and then the scheduled task to process, each update fixed bar number is good. For example, the timing of the script every start, according to the criteria to query, each check 1000, update status for overdue unpaid, if the results of less than 1000 or no results, it does not need to check the next time.

Your question is not to shoot after half an hour without payment on the deletion, if so, the following points of thinking you can see

    1. NoSQL, which needs to be persistent, uses Redis to set the expiration time and automatically delete it after the time (this is the case for NoSQL features), and your foreground program needs to be judged.
      2. If Redis is not allowed (that is, with MySQL-type relational database), but also the time to set the expiration time stamp, and then on the order-related pages manually whether to expire (if the Expiration time and order in a table, will not waste resources ah, take more than one field)

Is my understanding wrong, why need crontab and message queue??

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.