I made a voting project, do not want to every vote to visit a database, want to update the database after a certain time, how should I do?

Source: Internet
Author: User
Tags bulk insert
Database delay Delay Voting

I made a voting project, do not want to every vote to visit the update database, want to update the database after a certain time, how should I do?


Reply to discussion (solution)

If the database is not updated immediately after the poll, does the result of the poll appear incorrect?

Real-time functionality, no need to bulk INSERT.

If the database is not updated immediately after the poll, does the result of the poll appear incorrect? I think it's a minute. Update database

The more straightforward way I can think of is:

Writes the result of the poll to a text file, either as an SQL statement (recommended) or as a simple dump of the data.

Run a cron job in the background, scan the software every minute, and filter what needs to be updated to the database with some markup (such as the maximum Id,timestamp last processed).

The voting results can be divided into an array of time periods, the array to write a temporary file, every time to extract the file, and then empty the file, with the 4 floor of the idea of the same!

Use the queue now! This should be very convenient, real-time data is also convenient ~

How about using caches like memcache?

Bulk read and write to database at a time and empty memcache

Make a B, write the data into table B, partition time to update the B data to a inside.

and 4 5, 7 floors. Create a temporary file store and then read it to the library in time.

Write to file and save to database?
So what's the use of a database?

I suggest you write the database directly.
The concurrency of a file is actually not good to handle.
And from the point of view of reading files and databases, I think the database is more convenient

The database is doing this. Your project is a very small project.

The MySQL memory table processes the data.

The more straightforward way I can think of is:

Writes the result of the poll to a text file, either as an SQL statement (recommended) or as a simple dump of the data.

Run a cron job in the background, scan the software every minute, and filter what needs to be updated to the database with some markup (such as the maximum Id,timestamp last processed).
That's what I'm doing with this idea.

The voting results can be divided into an array of time periods, the array to write a temporary file, every time to extract the file, and then empty the file, with the 4 floor of the idea of the same!
What do you mean by extracting files every once in a while? PHP programs are triggered to run after the bar, how can you automatically extract this file every time?

  • 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.