Export millions of data to csv with multiple processes in one minute and upload to oss

藏色散人
Release: 2023-04-20 15:32:01
forward
1452 people have browsed it

This article brings you relevant knowledge about PHP. It mainly introduces how to export millions of data to csv and upload it to oss in more than one minute. Friends who are interested can take a look. ,I hope everyone has to help.

Requirements

  1. The product needs to export the walking logs of certain users of a certain team to a csv file, and it must be in one file, and the speed must be fast and not too time-consuming.

Problem

  1. Logs often mean large amounts of data.
  2. To import it into a file, even if the data volume is large, it can still be solved. It is nothing more than paging query and writing to csv.
  3. The speed is fast and the time is short. It can also be solved by exporting multiple files through multiple processes. There is nothing difficult, but the requirement is one file!

Solution idea

  1. First query the total amount of data to be exported
  2. Put it into the batch queue to start multiple consumer queries and write into multiple csv.
  3. Record the specific csv path and file name written by each queue when posting to the queue.
  4. Use the characteristics of the batch queue to merge the multiple csv recorded in the previous step into one csv in order when the execution is completed.
  5. After the merging is completed, delete the multiple csv before merging. Keep the merged csv and upload it to oss

Result

After testing more than 500,000 data, each queue in the batch queue is assigned 50,000 pieces of data to process, and a process is completed It takes less than a minute. How fast this method is depends on how many consumers and processes the server can start. When I tested, I used the automatic strategy, and the maximum was 8 consumers executing at the same time.

Export millions of data to csv with multiple processes in one minute and upload to oss

Recommended study: "laravel video tutorial"

The above is the detailed content of Export millions of data to csv with multiple processes in one minute and upload to oss. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!