Лучшие практики для массовой загрузки данных

На этой странице описаны лучшие практики массовой загрузки данных в Cloud Firestore с помощью таких инструментов, как mongoimport .

Cloud Firestore is a highly distributed system offering automatic scaling to meet the needs of your business. Cloud Firestore dynamically splits and combines your data based on the load received by the system.

Load-based splitting happens automatically without any required pre-configuration. The Cloud Firestore load-based splitting system has some important, unique characteristics compared to other document databases that are important to keep in mind as you model your data.

Cloud Firestore 's distributed nature can require changing some design choices to change, particularly for workloads that were optimized for databases where the primary replica is the bottleneck for write throughput.

Передовые методы

Workloads that process large amounts of data in a single threaded client can create a bottleneck. Clients might be able to use single threading to bulk load data, as the throughput of the client and server are similarly matched. A Cloud Firestore database can handle significantly more parallelism, but this requires that you configure clients to send requests in parallel.

mongoimport

When using the mongoimport tool, requests are made sequentially by default. To improve the load time into Cloud Firestore , set the number of workers with the --numInsertionWorkers flag. The correct setting might require tuning based on the size of your client, but we generally recommend starting with at least 32 .

асинхронное программирование

При разработке собственного программного обеспечения с использованием операций, совместимых с MongoDB, вы можете повысить параллелизм следующими способами:

  • Async frameworks : using async frameworks let you process and respond to requests in parallel. It is not necessary to develop any complex pooling or queuing when making calls to your database. Each request flow can use independent connections and make their database calls in parallel.
  • Используйте решения для параллельных вычислений : с помощью таких сервисов, как Cloud Run , ваша система может масштабировать количество вычислительных процессов, необходимых для обработки данных.

Кратковременные сбои

При работе с крупной распределенной системой, такой как Cloud Firestore , вы можете столкнуться с временными сбоями, такими как перебои в сети или конфликты при доступе к документу.

При массовой загрузке больших объемов информации важно поддерживать стратегию повторных попыток для неудачных операций записи, чтобы не прерывать основную операцию массовой загрузки.