From e52a3157529ee415a0325551468558925abf1e06 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 10 Jan 2023 10:29:50 +0300 Subject: [PATCH] [#50] Use `native.connect` timeouts everywhere Also, use defaults from the SDK itself, allow user to provide 0. Signed-off-by: Evgenii Stratonikov --- README.md | 4 +++- examples/native.js | 2 +- examples/native_onsite.js | 2 +- internal/native/native.go | 9 +++++++-- scenarios/run_scenarios.md | 4 ++++ scenarios/verify.js | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90e1ca0..a640c8e 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,12 @@ xk6 build --with github.com/TrueCloudLab/xk6-frostfs=. Create native client with `connect` method. Arguments: - frostfs storage node endpoint - hex encoded private key (empty value produces random key) +- dial timeout in seconds (0 for the default value) +- stream timeout in seconds (0 for the default value) ```js import native from 'k6/x/frostfs/native'; -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "", 0, 0) ``` ### Methods diff --git a/examples/native.js b/examples/native.js index d60fedc..45bb5fc 100644 --- a/examples/native.js +++ b/examples/native.js @@ -3,7 +3,7 @@ import {fail} from "k6"; import native from 'k6/x/frostfs/native'; const payload = open('../go.sum', 'b'); -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb", 0, 0) export const options = { stages: [ diff --git a/examples/native_onsite.js b/examples/native_onsite.js index 267080c..0ef6ce7 100644 --- a/examples/native_onsite.js +++ b/examples/native_onsite.js @@ -3,7 +3,7 @@ import native from 'k6/x/frostfs/native'; const payload = open('../go.sum', 'b'); const container = "AjSxSNNXbJUDPqqKYm1VbFVDGCakbpUNH8aGjPmGAH3B" -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "", 0, 0) const frostfs_obj = frostfs_cli.onsite(container, payload) export const options = { diff --git a/internal/native/native.go b/internal/native/native.go index 3e974c7..f09b729 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -74,8 +74,13 @@ func (n *Native) Connect(endpoint, hexPrivateKey string, dialTimeout, streamTime var prmDial client.PrmDial prmDial.SetServerURI(endpoint) - prmDial.SetTimeout(time.Duration(dialTimeout) * time.Second) - prmDial.SetStreamTimeout(time.Duration(streamTimeout) * time.Second) + if dialTimeout > 0 { + prmDial.SetTimeout(time.Duration(dialTimeout) * time.Second) + } + + if streamTimeout > 0 { + prmDial.SetStreamTimeout(time.Duration(streamTimeout) * time.Second) + } err = cli.Dial(prmDial) if err != nil { diff --git a/scenarios/run_scenarios.md b/scenarios/run_scenarios.md index 0a42706..c008cc6 100644 --- a/scenarios/run_scenarios.md +++ b/scenarios/run_scenarios.md @@ -39,6 +39,8 @@ Options (in addition to the common options): * `DELETERS` - number of VUs performing delete operations (using deleters requires that options `DELETE_AGE` and `REGISTRY_FILE` are specified as well). * `DELETE_AGE` - age of object in seconds before which it can not be deleted. This parameter can be used to control how many objects we have in the system under load. * `SLEEP_DELETE` - time interval (in seconds) between deleting VU iterations. + * `DIAL_TIMEOUT` - timeout to connect to a node (in seconds). + * `STREAM_TIMEOUT` - timeout for a single stream message for `PUT`/`GET` operations (in seconds). ## HTTP @@ -121,6 +123,8 @@ Options: * `REGISTRY_FILE` - database file from which objects for verification should be read. * `SLEEP` - time interval (in seconds) between VU iterations. * `SELECTION_SIZE` - size of batch to select for deletion (default: 1000). + * `DIAL_TIMEOUT` - timeout to connect to a node (in seconds). + * `STREAM_TIMEOUT` - timeout for a single stream message for `PUT`/`GET` operations (in seconds). ## Verify preset diff --git a/scenarios/verify.js b/scenarios/verify.js index a5c16ab..43bb018 100644 --- a/scenarios/verify.js +++ b/scenarios/verify.js @@ -25,7 +25,7 @@ let grpc_client = undefined; if (__ENV.GRPC_ENDPOINTS) { const grpcEndpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpcEndpoint = grpcEndpoints[Math.floor(Math.random() * grpcEndpoints.length)]; - grpc_client = native.connect(grpcEndpoint, ''); + grpc_client = native.connect(grpcEndpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 0, __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 0); } // Connect to random S3 endpoint