[#3] native: Configure buffer size

Default value is increased up to 64 KiB.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-05-25 11:22:40 +03:00 committed by Alex Vanin
parent 41dc2c8a54
commit faba352e36
3 changed files with 35 additions and 18 deletions

View file

@ -46,6 +46,8 @@ const neofs_cli = native.connect("s01.neofs.devenv:8080", "")
``` ```
#### Methods #### Methods
- `setBufferSize(size)`. Sets internal buffer size for data upload and
download. Default is 64 KiB.
- `put(container_id, headers, payload)`. Returns dictionary with `success` - `put(container_id, headers, payload)`. Returns dictionary with `success`
boolean flag, `object_id` string, and `error` string. boolean flag, `object_id` string, and `error` string.
- `get(container_id, object_id)`. Returns dictionary with `success` boolean - `get(container_id, object_id)`. Returns dictionary with `success` boolean

View file

@ -30,10 +30,11 @@ import (
type ( type (
Client struct { Client struct {
vu modules.VU vu modules.VU
key ecdsa.PrivateKey key ecdsa.PrivateKey
tok session.Object tok session.Object
cli *client.Client cli *client.Client
bufsize int
} }
PutResponse struct { PutResponse struct {
@ -48,16 +49,28 @@ type (
} }
PreparedObject struct { PreparedObject struct {
vu modules.VU vu modules.VU
key ecdsa.PrivateKey key ecdsa.PrivateKey
cli *client.Client cli *client.Client
bufsize int
hdr object.Object hdr object.Object
payload []byte payload []byte
} }
) )
const defaultPutBufferSize = 4 * 1024 const defaultBufferSize = 64 * 1024
func (c *Client) SetBufferSize(size int) {
if size < 0 {
panic("buffer size must be positive")
}
if size == 0 {
c.bufsize = defaultBufferSize
} else {
c.bufsize = size
}
}
func (c *Client) Put(inputContainerID string, headers map[string]string, payload goja.ArrayBuffer) PutResponse { func (c *Client) Put(inputContainerID string, headers map[string]string, payload goja.ArrayBuffer) PutResponse {
var containerID cid.ID var containerID cid.ID
@ -93,7 +106,7 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
o.SetOwnerID(&owner) o.SetOwnerID(&owner)
o.SetAttributes(attrs...) o.SetAttributes(attrs...)
resp, err := put(c.vu, defaultPutBufferSize, c.cli, &tok, &o, payload.Bytes()) resp, err := put(c.vu, c.bufsize, c.cli, &tok, &o, payload.Bytes())
if err != nil { if err != nil {
return PutResponse{Success: false, Error: err.Error()} return PutResponse{Success: false, Error: err.Error()}
} }
@ -106,7 +119,7 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
func (c *Client) Get(inputContainerID, inputObjectID string) GetResponse { func (c *Client) Get(inputContainerID, inputObjectID string) GetResponse {
var ( var (
buf = make([]byte, 4*1024) buf = make([]byte, c.bufsize)
sz int sz int
) )
@ -216,9 +229,10 @@ func (c *Client) Onsite(inputContainerID string, payload goja.ArrayBuffer) Prepa
} }
return PreparedObject{ return PreparedObject{
vu: c.vu, vu: c.vu,
key: c.key, key: c.key,
cli: c.cli, cli: c.cli,
bufsize: c.bufsize,
hdr: *obj, hdr: *obj,
payload: data, payload: data,
@ -247,7 +261,7 @@ func (p PreparedObject) Put(headers map[string]string) PutResponse {
return PutResponse{Success: false, Error: err.Error()} return PutResponse{Success: false, Error: err.Error()}
} }
_, err = put(p.vu, defaultPutBufferSize, p.cli, nil, &obj, p.payload) _, err = put(p.vu, p.bufsize, p.cli, nil, &obj, p.payload)
if err != nil { if err != nil {
return PutResponse{Success: false, Error: err.Error()} return PutResponse{Success: false, Error: err.Error()}
} }

View file

@ -116,9 +116,10 @@ func (n *Native) Connect(endpoint, wif string) (*Client, error) {
objGetDuration, _ = registry.NewMetric("neofs_obj_get_duration", metrics.Trend, metrics.Time) objGetDuration, _ = registry.NewMetric("neofs_obj_get_duration", metrics.Trend, metrics.Time)
return &Client{ return &Client{
vu: n.vu, vu: n.vu,
key: pk.PrivateKey, key: pk.PrivateKey,
tok: tok, tok: tok,
cli: &cli, cli: &cli,
bufsize: defaultBufferSize,
}, nil }, nil
} }