[#3] native: Configure buffer size

Default value is increased up to 64 KiB.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
lorem-ipsum
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
- `setBufferSize(size)`. Sets internal buffer size for data upload and
download. Default is 64 KiB.
- `put(container_id, headers, payload)`. Returns dictionary with `success`
boolean flag, `object_id` string, and `error` string.
- `get(container_id, object_id)`. Returns dictionary with `success` boolean

View File

@ -34,6 +34,7 @@ type (
key ecdsa.PrivateKey
tok session.Object
cli *client.Client
bufsize int
}
PutResponse struct {
@ -51,13 +52,25 @@ type (
vu modules.VU
key ecdsa.PrivateKey
cli *client.Client
bufsize int
hdr object.Object
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 {
var containerID cid.ID
@ -93,7 +106,7 @@ func (c *Client) Put(inputContainerID string, headers map[string]string, payload
o.SetOwnerID(&owner)
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 {
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 {
var (
buf = make([]byte, 4*1024)
buf = make([]byte, c.bufsize)
sz int
)
@ -219,6 +232,7 @@ func (c *Client) Onsite(inputContainerID string, payload goja.ArrayBuffer) Prepa
vu: c.vu,
key: c.key,
cli: c.cli,
bufsize: c.bufsize,
hdr: *obj,
payload: data,
@ -247,7 +261,7 @@ func (p PreparedObject) Put(headers map[string]string) PutResponse {
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 {
return PutResponse{Success: false, Error: err.Error()}
}

View File

@ -120,5 +120,6 @@ func (n *Native) Connect(endpoint, wif string) (*Client, error) {
key: pk.PrivateKey,
tok: tok,
cli: &cli,
bufsize: defaultBufferSize,
}, nil
}