[#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:
parent
41dc2c8a54
commit
faba352e36
3 changed files with 35 additions and 18 deletions
|
@ -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
|
||||||
|
|
|
@ -34,6 +34,7 @@ type (
|
||||||
key ecdsa.PrivateKey
|
key ecdsa.PrivateKey
|
||||||
tok session.Object
|
tok session.Object
|
||||||
cli *client.Client
|
cli *client.Client
|
||||||
|
bufsize int
|
||||||
}
|
}
|
||||||
|
|
||||||
PutResponse struct {
|
PutResponse struct {
|
||||||
|
@ -51,13 +52,25 @@ type (
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -219,6 +232,7 @@ func (c *Client) Onsite(inputContainerID string, payload goja.ArrayBuffer) Prepa
|
||||||
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()}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,5 +120,6 @@ func (n *Native) Connect(endpoint, wif string) (*Client, error) {
|
||||||
key: pk.PrivateKey,
|
key: pk.PrivateKey,
|
||||||
tok: tok,
|
tok: tok,
|
||||||
cli: &cli,
|
cli: &cli,
|
||||||
|
bufsize: defaultBufferSize,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue