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

Several code/performance improvements #225

Merged
merged 6 commits into from
Jun 26, 2024
Merged

Conversation

cthulhu-rider
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

Attention: Patch coverage is 5.40541% with 70 lines in your changes missing coverage. Please review.

Project coverage is 22.21%. Comparing base (fb1b3ff) to head (1370519).
Report is 1 commits behind head on master.

Files Patch % Lines
handlers/objects.go 0.00% 31 Missing ⚠️
handlers/util.go 0.00% 16 Missing ⚠️
handlers/newObjects.go 0.00% 13 Missing ⚠️
handlers/api.go 33.33% 6 Missing ⚠️
cmd/neofs-rest-gw/config.go 20.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #225      +/-   ##
==========================================
+ Coverage   22.11%   22.21%   +0.09%     
==========================================
  Files          17       17              
  Lines        3305     3300       -5     
==========================================
+ Hits          731      733       +2     
+ Misses       2439     2431       -8     
- Partials      135      136       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

roman-khimov
roman-khimov previously approved these changes Jun 25, 2024
handlers/api.go Outdated Show resolved Hide resolved
handlers/api.go Outdated Show resolved Hide resolved
handlers/objects.go Outdated Show resolved Hide resolved
Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
cmd/neofs-rest-gw/config.go Show resolved Hide resolved
cmd/neofs-rest-gw/config.go Outdated Show resolved Hide resolved
Several API handlers call `io.CopyBuffer` passing buffer of static
parameter size. Previously, this parameter was of int64 type and
converted from uint64 `MaxObjectSize` (M) NeoFS network setting. In
practice, such a numerical cast was quite safe: M is normally positive
and not bigger than int64. However, since this parameter is used to
allocated buffers passed to `io.CopyBuffer`, there were rooms for panic:
 - zero value could cause specific `io.CopyBuffer` panic
 - int64 overflow could cause `make` panic on negative len input

From now parameter type is uint64, so negative case is prevented. Zero
case is still possible at the type level, so it is replaced by default
at 4MB at the app layer.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
Previously, `NewUploadContainerObject` handler always allocated buffer
of max object size (NeoFS setting) to copy request body. In practice,
this value is pretty big to be buffer size (e.g. it is 64M usually now).
Moreover, for requests with a smaller body, part of the buffer remained
simply redundant.

From now buffer size is determined according to `Content-Length` header.
This will significantly reduce the memory consumption of small queries.
However, the header will cover only part of the cases: the previous
behavior is left in case of its absence or MaxObjectSize overflow.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
Continues f1f7ab4 for
`UploadContainerObject`. Size of the file from the multipart form is at
hand, so using it to allocate a buffer will improve performance on small
volumes.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
According to the code, operand cannot be nil. Otherwise, the
unconditional `io.CopyBuffer` call within the same method would be
unsafe and removed if-condition only raised suspicions of potential
panic.

Deferred action is also moved "closer" to the file init.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
`NewUploadContainerObject`, `UploadContainerObject` and `PutObject` put
objects to the NeoFS in a very similar way.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
@roman-khimov roman-khimov merged commit b482739 into master Jun 26, 2024
13 of 14 checks passed
@roman-khimov roman-khimov deleted the fast-improvements branch June 26, 2024 16:07
@roman-khimov roman-khimov modified the milestones: v0.11.0, v0.10.1 Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants