Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

504 Deadline Exceeded: BigQuery to Firestore Collection using Python in Batch Writes Mode #873

Open
sanket-coditas opened this issue Mar 1, 2024 · 0 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@sanket-coditas
Copy link

Hi,

I am working on the setup as mentioned below and getting the error:
"504 Deadline Exceeded"

  1. Read approx. 10k rows from BigQuery in Cloud Function using Python
  2. Write those 10k rows to a Firestore collection using the below code -
    -- Batch size is selected as 500
    -- It forms smaller batches (approx. 20) and loads the data
max_batch_size = 500
for i in range(0, len(records), max_batch_size):
	batch_number += 1
	batch = firestore_client.batch()
	for data in records[i:i+max_batch_size]:
		doc_ref = collection_ref.document()
		batch.set(doc_ref, data)
	try:
		batch.commit()
	except GoogleAPIError as error:
		print(f"An error occurred: {error}")

I am consistently facing the "504 Deadline Exceeded" error.

Things that I have already tried -

  1. Changing the batch size to 1000, it still fails. Changing to 200, it becomes very slow and sometimes fails as well.
  2. Adding index to the Firestore collection (? Not sure about this since adding/removing index would help)

A few questions:

  1. Is there any better way to handle this error? I am unable to find any consistent behavior.
  2. As I know, the batch.commit() timeout is 60s, how can I change it to a bigger value, also is this recommended?

Can someone please help?

Thank you in advanced!
Sanket Kelkar

@parthea parthea transferred this issue from googleapis/google-cloud-python Mar 4, 2024
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Projects
None yet
Development

No branches or pull requests

2 participants