Skip to content

Conversation

@SilianZ
Copy link
Member

@SilianZ SilianZ commented Jul 23, 2025

Summary

  • stream downloads to disk to avoid large memory usage
  • generate measure files incrementally
  • allow storage backends to accept generic binary streams
  • prune logs in MemoryDataBase
  • lower dashboard monitoring overhead

Testing

  • python -m py_compile $(git ls-files '*.py')
  • pytest -q

https://chatgpt.com/codex/tasks/task_e_6880ab2599f0832b932213ef03537ec5

@SilianZ SilianZ requested a review from Copilot July 23, 2025 11:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes resource usage by modifying storage backends to accept generic binary streams instead of specific BytesIO objects, enabling streaming downloads to disk and incremental file generation to reduce memory consumption. It also implements memory management improvements in the database and dashboard monitoring.

Key changes:

  • Modified storage backend interfaces to accept BinaryIO instead of io.BytesIO for more flexible stream handling
  • Changed download and file generation logic to use temporary files instead of in-memory buffers
  • Implemented log pruning in MemoryDatabase using a bounded deque and reduced dashboard monitoring overhead

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/utils.py Updated AvroParser to accept both bytes and BinaryIO streams
core/storage/*.py Modified upload methods to accept BinaryIO instead of BytesIO
core/storage/abc.py Changed measure file generation to use temporary files incrementally
core/database/memory.py Implemented log pruning using bounded deque
core/dashboard.py Made update method async and reduced CPU monitoring overhead
core/cluster.py Changed file downloads to use temporary files instead of memory buffers

Comment on lines +246 to 248
tmp_file.seek(0)
await self.upload_storage(file, tmp_file, size)
self.update_success()
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seek(0) call is not within the try block but should be, as it's part of the file processing logic that could fail. If an exception occurs before this line, the file position will be incorrect for the upload_storage call.

Suggested change
tmp_file.seek(0)
await self.upload_storage(file, tmp_file, size)
self.update_success()
tmp_file.seek(0)
await self.upload_storage(file, tmp_file, size)
self.update_success()

Copilot uses AI. Check for mistakes.
async for chunk in resp.content.iter_chunked(1024 * 1024 * 4):
tmp.write(chunk)
tmp.seek(0)
with zstd.open(tmp, 'rb') as zf:
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary file tmp is not properly closed after use. The context manager only handles the zstd file, but the underlying temporary file should also be closed to free resources.

Copilot uses AI. Check for mistakes.
Comment on lines +201 to +214
tmp = tempfile.TemporaryFile()
chunk = b"\x00" * (1024 * 1024)
remain = size
while remain > 0:
w = min(remain, len(chunk))
tmp.write(chunk[:w])
remain -= w
tmp.seek(0)
await self.upload(
path,
io.BytesIO(b"\x00" * size),
tmp,
size
)
tmp.close()
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary file should be closed in a try-finally block or using a context manager to ensure it's always closed even if an exception occurs during upload.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants