You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BigQuery: Decrease peak memory usage of to_dataframe #8107
via `pd.read_parquet(), using the gzip-imported dataframe -> exported as parquet as sourcefile
I suspect that if we del pages as we finish converting them to dataframe in the to_dataframe loop, we can decrease peak memory usage / overshoot by quite a lot.
TL;DR - I profiled the code again on the baseball public data using different BQ client versions and with(out) the bqstorage client, and the latter makes a huge difference.
fromgoogle.cloudimportbigquery@profiledefrun_mem_test():
client=bigquery.Client()
table_path="bigquery-public-data.baseball.games_post_wide"query_string=f"SELECT * from `{table_path}` LIMIT 4000"# Use the BigQuery Storage API to speed-up downloads of large tables.df=client.query(query_string).to_dataframe(create_bqstorage_client=False) # or Trueprint(df.info())
print(f"Dataframe memory usage {table_path}: {df.memory_usage().sum()}")
if__name__=="__main__":
run_mem_test()
Activity
tswast commentedon Jan 10, 2020
Now that we're using pyarrow with the BQ Storage API, I suspect that memory usage has decreased by quite a bit.
It's worth re-running these tests to see if we can close this issue out.
plamut commentedon Jan 20, 2020
TL;DR - I profiled the code again on the baseball public data using different BQ client versions and with(out) the bqstorage client, and the latter makes a huge difference.
Versions used
Test script
Testing procedure
Install the tools:
Run the profiler and visualize the results:
I compared the current BigQuery client version from
masterwith version1.12.1(the latest released version at the time this issue was created).Results
Option
create_bqstorage_client=False:BigQuery client 1.21.1

BigQuery client master

Option
create_bqstorage_client=True:BigQuery client 1.21.1

BigQuery client master

Summary
There doesn't seem to be much difference when not using the bqstorage client, although the peak memory usage has decreased a bit.
On the other hand, memory savings are huge when bqstorage client is used. The latter used less than half as much memory in tests.
plamut commentedon Jan 22, 2020
@tswast I suppose the memory consumption improvement is large enough to close this issue?
tswast commentedon Jan 23, 2020
👍
Let's close now that https://github.com/googleapis/google-cloud-python/issues/10185 is open, which will remove code paths where we have less control over memory usage.