n+ the problem of synchronizing consumption, to discuss how to avoid bad business

Source: Internet
Author: User

Encounter a comparison of the problem of egg, is the same time come over n concurrent calls, how to ensure that the simultaneous consumption of 30 minutes, and not more than 30 minutes of bad debts.
Reprint Please specify source: http://blog.csdn.net/supera_li/article/details/45506583

1. Problem Modeling:
N people call at the same time, 30 minutes remaining. Guaranteed 30 minutes of simultaneous consumption, after consumption, the phone will be forced to hang up. Without creating bad debts.

2. Solution:
Synchronization issues are not synchronized with the minimum start time. That is, I have to have a final threshold to control the last point time slices are not assigned to multiple users, only one user is supported online. Also, because you want to support a user, you must have a synchronization queue that maintains the order of requests to handle requests for rejection.

Assumed parameters:
Minimum start time parameter s=5.
N Synchronous Queue Q, which is the N-person queue that requests the server's remaining time per minute.

N Scale classification and time slice allocation algorithm:
1). n>30, the person after n-30 refused the request. The average distribution of 30 people is 1min.
2). n belongs to [30-s,30] interval, average n person assigns 1min
3). N<30-s, i.e. n belongs to (1,30-s) interval,
The first request n queues into q,q to detect if n overflows the remaining time, and the relationship between the remaining minutes after the next allocation is detected with the 30-s, and the DB is updated. Allocates a time allocation sum of n minutes.
Second allocation sum n*2 (assuming not hang up, continue into Q, perform detection judgment, update db)
The break termination condition is a detection failure. Complete the sync issue.
After the synchronization problem is complete, the remaining minutes are in the [30-s,30] interval and are not synchronized in accepting N requests. Only single-user calls are supported.

n+ the problem of synchronizing consumption, to discuss how to avoid bad business

Related Article

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.