Title: increased memory usage in 2.4.0 · Issue #394 · googleapis/python-bigquery · GitHub
Open Graph Title: increased memory usage in 2.4.0 · Issue #394 · googleapis/python-bigquery
X Title: increased memory usage in 2.4.0 · Issue #394 · googleapis/python-bigquery
Description: Version 2.4.0 of the library is allocating much more memory that the previous version, 2.3.1, when running multiple queries. In particular, it seems that the QueryJob object is retaining the results of the query internally, and that memo...
Open Graph Description: Version 2.4.0 of the library is allocating much more memory that the previous version, 2.3.1, when running multiple queries. In particular, it seems that the QueryJob object is retaining the result...
X Description: Version 2.4.0 of the library is allocating much more memory that the previous version, 2.3.1, when running multiple queries. In particular, it seems that the QueryJob object is retaining the result...
Opengraph URL: https://github.com/googleapis/python-bigquery/issues/394
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"increased memory usage in 2.4.0","articleBody":"Version 2.4.0 of the library is allocating much more memory that the previous version, 2.3.1, when running multiple queries.\r\nIn particular, it seems that the `QueryJob` object is retaining the results of the query internally, and that memory is not deallocated.\r\n\r\nI think that the problem is related to https://github.com/googleapis/python-bigquery/pull/374.\r\n\r\n#### Environment details\r\n\r\n - macOS 11.0.1 (also observing this on Linux in a production environment)\r\n - Python version: 3.8.6\r\n - pip version: 20.1.1 \r\n - `google-cloud-bigquery` version: 2.4.0\r\n\r\n#### Steps to reproduce\r\n\r\nRun the script in the code example with `google-cloud-bigquery` 2.4.0 and 2.3.1 versions.\r\nYou will also need to install:\r\n```\r\ngoogle-cloud-bigquery-storage==2.1.0\r\npandas==1.1.4\r\npsutil==5.7.3\r\n```\r\n\r\nThe outputs on my machine are:\r\n\r\nWith 2.4.0:\r\n```\r\nInitial memory used: 77 MB\r\nMemory used: 642 MB\r\nMemory used: 875 MB\r\nMemory used: 1117 MB\r\nMemory used: 1342 MB\r\nMemory used: 1568 MB\r\nMemory used: 1792 MB\r\nMemory used: 2039 MB\r\nMemory used: 2265 MB\r\nMemory used: 2505 MB\r\nMemory used: 2725 MB\r\n```\r\n\r\nWith 2.3.1:\r\n\r\n```\r\nInitial memory used: 77 MB\r\nMemory used: 97 MB\r\nMemory used: 98 MB\r\nMemory used: 99 MB\r\nMemory used: 99 MB\r\nMemory used: 99 MB\r\nMemory used: 99 MB\r\nMemory used: 100 MB\r\nMemory used: 101 MB\r\nMemory used: 101 MB\r\nMemory used: 101 MB\r\n```\r\n\r\n#### Code example\r\n\r\nPlease note that we are storing a reference to the `QueryJob` objects, but **not** to the resulting DataFrames.\r\n\r\n```python\r\nimport os\r\n\r\nimport psutil\r\nfrom google.cloud import bigquery\r\n\r\nif __name__ == '__main__':\r\n client = bigquery.Client()\r\n\r\n process = psutil.Process(os.getpid())\r\n print(f\"Initial memory used: {process.memory_info().rss / 1e6:.0f} MB\")\r\n\r\n jobs = []\r\n\r\n for i in range(10):\r\n job = client.query(\"SELECT x FROM UNNEST(GENERATE_ARRAY(1, 1000000)) AS x\")\r\n job.result().to_dataframe()\r\n jobs.append(job)\r\n print(f\"Memory used: {process.memory_info().rss / 1e6:.0f} MB\")\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/pietrodn","@type":"Person","name":"pietrodn"},"datePublished":"2020-11-19T08:05:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/394/python-bigquery/issues/394"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:10fb4cf8-0ffd-a9ae-d0b4-63aaf70d8b82 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D438:BAE90:1149D14:177BEA6:6A4F0F1A |
| html-safe-nonce | 5bc9faeb0378f0b8403d1fa3fe8c021f325da9932fe43f547708328245a67488 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDM4OkJBRTkwOjExNDlEMTQ6MTc3QkVBNjo2QTRGMEYxQSIsInZpc2l0b3JfaWQiOiI1NzA2NTkxNTY2MTQ0OTMzNjU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cf14cf25470b7d64758b2b0d01b27f92dc840a18f4cbedd1251208cc6dabff29 |
| hovercard-subject-tag | issue:746344957 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-bigquery/394/issue_layout |
| twitter:image | https://opengraph.githubassets.com/02ac186a684590280a0cdc7c51ec5c61c0e45ee60907a3cb7983b12553022424/googleapis/python-bigquery/issues/394 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/02ac186a684590280a0cdc7c51ec5c61c0e45ee60907a3cb7983b12553022424/googleapis/python-bigquery/issues/394 |
| og:image:alt | Version 2.4.0 of the library is allocating much more memory that the previous version, 2.3.1, when running multiple queries. In particular, it seems that the QueryJob object is retaining the result... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pietrodn |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-bigquery git https://github.com/googleapis/python-bigquery.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992475 |
| octolytics-dimension-repository_nwo | googleapis/python-bigquery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992475 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-bigquery |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width