Skip to content

Conversation

@j2rong4cn
Copy link
Member

@j2rong4cn j2rong4cn commented Jul 3, 2025

添加配置选项 max_buffer_limitMB

  • 限制单个buffer的大小
    自动: -1 (默认):5%的总内存
    关闭:0
    自定义:大于0 单位为MB
  • 现阶段主要用于上传,如果单个分片或单文件超过该大小就会先缓存到临时文件再上传

优化以下驱动在上传时的内存和存储占用

115open、123、123open、aliyun_open、google_drive、cloudreve、cloudreve_v4、onedrive、onedrive_app、doubao、189pc

@github-actions
Copy link

github-actions bot commented Jul 3, 2025

⚠️ PR 标题需以 feat(): , docs(): , fix(): , style(): , refactor(): 其中之一开头,例如:feat(component): 新增功能⚠️ The PR title must start with feat(): , docs(): , fix(): , style(): , or refactor(): . For example: feat(component): add new feature.

@j2rong4cn j2rong4cn changed the title pref: optimize upload perf: optimize upload Jul 3, 2025
@j2rong4cn j2rong4cn marked this pull request as draft July 12, 2025 10:13
@j2rong4cn j2rong4cn mentioned this pull request Jul 24, 2025
8 tasks
@j2rong4cn j2rong4cn marked this pull request as ready for review August 2, 2025 15:50
@elysia-best elysia-best requested a review from Copilot August 5, 2025 13:27
Copy link
Contributor

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 adds a configurable buffer limit feature to optimize memory usage during uploads and improves memory/storage efficiency for multiple drivers. The main change introduces a max_buffer_limitMB configuration option that automatically defaults to 5% of total memory, can be disabled with 0, or set to a custom value in MB.

  • Added max_buffer_limitMB configuration with automatic memory-based sizing
  • Optimized upload operations for 11 drivers to use streaming readers instead of memory buffers
  • Replaced string HTTP method literals with constants for consistency

Reviewed Changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/conf/config.go Added MaxBufferLimit configuration field with default -1
internal/bootstrap/config.go Implemented automatic buffer limit calculation based on system memory
internal/stream/util.go Added StreamSectionReader for efficient memory management during uploads
drivers/*/util.go Replaced memory buffering with streaming section readers for upload operations
pkg/errgroup/errgroup.go Enhanced error group with ordered execution and lifecycle management
pkg/singleflight/var.go Changed from ErrorGroup to AnyGroup for better type flexibility
Comments suppressed due to low confidence (1)

internal/stream/util.go:199

  • [nitpick] The parameter name 'bufMaxLen' is unclear. Consider renaming to 'maxBufferSize' or 'bufferSizeLimit' to better indicate it represents the maximum buffer size.
func NewStreamSectionReader(file model.FileStreamer, bufMaxLen int) (*StreamSectionReader, error) {

var buf []byte
if cache == nil {
if off != ss.off {
return nil, fmt.Errorf("stream not cached: request offset %d != current offset %d", off, ss.off)
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

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

[nitpick] The error message could be more descriptive about why this condition matters. Consider adding context about the streaming nature of the reader and why sequential access is required.

Suggested change
return nil, fmt.Errorf("stream not cached: request offset %d != current offset %d", off, ss.off)
return nil, fmt.Errorf("stream not cached: sequential access required for streaming reader (requested offset %d, current offset %d). Random access is only supported when the stream is fully cached.", off, ss.off)

Copilot uses AI. Check for mistakes.
@j2rong4cn j2rong4cn merged commit 8cf1518 into main Aug 5, 2025
8 checks passed
@j2rong4cn j2rong4cn deleted the pref-upload branch August 5, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants