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

SmallBank benchmark implementation #45

Merged
merged 32 commits into from
Aug 16, 2021
Merged

SmallBank benchmark implementation #45

merged 32 commits into from
Aug 16, 2021

Conversation

supl
Copy link
Collaborator

@supl supl commented Aug 3, 2021

This PR implements the smallbank applications as benchmark tools.

@supl supl force-pushed the DLT-9604 branch 2 times, most recently from 074d589 to c0d5772 Compare August 3, 2021 06:17
@supl supl marked this pull request as ready for review August 4, 2021 05:19
@supl supl requested review from feeblefakie and jnmt August 4, 2021 05:20
@supl
Copy link
Collaborator Author

supl commented Aug 4, 2021

@feeblefakie @jnmt
Please review this PR.

I copied related contracts from the caliper project, and also have a default client.properties.json file.
I don't use the yargs package for parsing CLI arguments to simplify package.json.

Please kindly advise.
Thank you :)

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good. Thank you!
Let me start off with some questions.

const [
properties,
numberOfAccount,
numberOfThread,
Copy link
Contributor

@feeblefakie feeblefakie Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is named for consistency, but I think it should be renamed to concurrency or something since Javascript is single-threaded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot, maybe adding a readme that details the execution order of the 3 programs would be helpful.

Thank you.
Will do.


const start = Date.now();
let from = start;
for (let i = 0; i < numberOfThread; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it using a single CPU core, right?
Java bench is using multiple cores using threads, so I'm wondering how we can compare them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feeblefakie

I think the async functions (the one that executes contracts) can leverage multiple CPU cores because they are non-blocking functions.
I am not exactly sure the details though.
Let me check this.

There is another way.
Node.js provides a concurrent practice called worker thread.
(It seems to me like a child process in runtime)
This for sure is leveraging multiple CPU cores.

If the async function practice doesn't really use multiple CPU cores,
then I will try to use worker thread to do it.

@feeblefakie feeblefakie requested a review from Torch3333 August 5, 2021 00:07
@feeblefakie
Copy link
Contributor

feeblefakie commented Aug 5, 2021

@supl Are we supposed to be able to run it just by running ./smallbank-bench?
It doesn't work for me, so I'm wondering if anything else is needed.
Sorry I'm a very beginner of node.js.

$ ./smallbank-bench
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '@scalar-labs/scalardl-javascript-sdk-base'
Require stack:
- /Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js
- /Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/benchmark/smallbank-bench
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js:10:5)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js',
    '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/benchmark/smallbank-bench'
  ]
}

@Torch3333
Copy link

Torch3333 commented Aug 5, 2021

@supl Are we supposed to be able to run it just by running ./smallbank-bench?
It doesn't work for me, so I'm wondering if anything else is needed.
Sorry I'm a very beginner of node.js.

$ ./smallbank-bench
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '@scalar-labs/scalardl-javascript-sdk-base'
Require stack:
- /Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js
- /Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/benchmark/smallbank-bench
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js:10:5)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/scalardl-node-client-sdk.js',
    '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/benchmark/smallbank-bench'
  ]
}

I ran into the same issue. I think you need to run npm install in /Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/

Copy link

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Thank you
I just left a minor comment.

I tested locally both with the auditor enabled and disabled and did not run into problem 🙂

Comment on lines 232 to 245
console.log(
'\t--properties PROPERTIES_FILE, --config PROPERTIES_FILE\n' +
'\t\tA configuration file in properties format.\n' +
'\t--num-accounts NUM_ACCOUNTS\n' +
'\t\tThe number of target accounts.\n' +
'\t--num-threads NUM_THREADS\n' +
'\t\tThe number of threads to run.\n' +
'\t--duration DURATION\n' +
'\t\tThe duration of benchmark in seconds\n' +
'\t--ramp-up-time RAMP_UP_TIME\n' +
'\t\tThe ramp up time in seconds.\n' +
'\t--operation OPERATION\n' +
'\t\ttransact_savings, ' +
'deposit_checking, send_payment, write_check, amalgamate',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the default value for each parameter be mentioned in the usage ?

Comment on lines 21 to 30
function usage() {
const path = require('path');
console.log(
'Usage: ' +
`${path.basename(process.argv[1])} ` +
'[--properties PROPERTIES_FILE, --config PROPERTIES_FILE] ' +
'[--num-accounts NUM_ACCOUNTS] ' +
'[--num-threads NUM_THREADS] ' +
'[-h, --help]',
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Should the default value for each parameter be mentioned in the usage ?

Copy link

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot, maybe adding a readme that details the execution order of the 3 programs would be helpful.

Copy link
Contributor

@jnmt jnmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good. Nice work! I was able to run the benchmark. Just a single comment on the discussion here (#45 (comment)).
JS async function does not run with multiple threads/CPUs. In the case of Caliper, child_process is used. Just for your information. Thanks.
https://github.com/scalar-labs/caliper/blob/ee6f3f2c5d69ad944ca753b6d5bb567849731285/packages/caliper-core/lib/master/orchestrators/worker-orchestrator.js#L548

@supl
Copy link
Collaborator Author

supl commented Aug 11, 2021

@jnmt
Jun, thanks for your recommendation.
It's really helpful!
I was thinking to use worker_threads to revise the application.
Unfortunately, the gRPC library seems not to support working with worker_threads.
I end up doing this by child_process as your advice.
Thank you so much :)

@feeblefakie
I revised the smallbank-loader.
Since it doesn't use threading but just async functions, so I changed the option to num-concurrencies for a clear idea.
The smallbank-bench uses child_process to achieve parallel processing, and I named the option num-processes.

Please review again.
Thank you :)

Copy link
Contributor

@jnmt jnmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Multi processes work well. It might not be a high priority but it would be happy if we could run loader with multi cores as well. Thank you.

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
Left one suggestion. PTAL when you get a chance.

}
break;

case '--num-processes':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we should have discussed the way to do it.

I think just using multiple processes is too efficient since a process is heavy so I think we should mix processes and threads (asynchronous multi-tasking) to make it comparable to the Java version.

One way to do this is that we let users specify concurrency and make the tool automatically divide the concurrency into multiple processes and "threads".
For example, if 16 concurrency is given on 4-core machine, we can create 4 processes to match with the number cores and create 4 "threads" for each process.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
I didn't think about that.
So, a sub-process will be in charge of a few concurrencies.
Unfortunately, we couldn't use worker_threads to implement it otherwise it might be more similar to Java's implementation.
I will revise smallbank-bench and smallbank-loader (according to Jun's feedback) by this idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know we don't have threads. I meant multitasking with async.

Copy link
Collaborator Author

@supl supl Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we should have discussed the way to do it.

I think just using multiple processes is too efficient since a process is heavy so I think we should mix processes and threads (asynchronous multi-tasking) to make it comparable to the Java version.

One way to do this is that we let users specify concurrency and make the tool automatically divide the concurrency into multiple processes and "threads".
For example, if 16 concurrency is given on 4-core machine, we can create 4 processes to match with the number cores and create 4 "threads" for each process.

What do you think?

@feeblefakie
I revised the implementation of smallbank-bench.
First, I rename the option name back to --num-concurrencies.
smallbank-bench now divides the requested concurrencies by the number of CPU,
then it forks subprocesses as the same number as CPU.
Each forked subprocess uses async functions with the number of divided concurrencies to run the benchmark.

I also revised smallbank-loader with the child_process mechanism.
I didn't use fork + async way for smallbank-loader because I think it doesn't matter that smallbank-loader does works too efficiently, so I used an easier way to revise it.

@jnmt
Jun, thank you for your advice.
I used child_process to revise smallbank-loader.
Now it can do jobs more efficiently too.

@feeblefakie
Copy link
Contributor

@supl I've played around with it but am facing some issues.
Even after npm install, I am facing the following error.

$ benchmark/smallbank-bench --properties ~/git/scalar/client/client.properties --num-accounts 100 --num-concurrencies 4 --duration 10  --ramp-up-time 1
0 tps
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
0 tps

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I left a suggestion.
I'm also facing some issues running it yet.

}
break;

case '--ramp-up-time':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I specified 0 for this, it still triggers the help. 0 is useful for testing, so it would be great if it is fixed!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

```

```
./smallbank-bench -h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be great if the help is shown when nothing is specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

@supl
Copy link
Collaborator Author

supl commented Aug 13, 2021

@supl I've played around with it but am facing some issues.
Even after npm install, I am facing the following error.

$ benchmark/smallbank-bench --properties ~/git/scalar/client/client.properties --num-accounts 100 --num-concurrencies 4 --duration 10  --ramp-up-time 1
0 tps
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/hiroyuki/Dropbox/doc/git/scalardl-node-client-sdk/smallbank-bench-worker'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
0 tps

This must be an issue related to the working directory.
Let me fix it.

Thank you for your testing :)

@supl
Copy link
Collaborator Author

supl commented Aug 13, 2021

@feeblefakie
I fixed the working directory issue.
The help is now shown when no argument is given and the ramp-up-time can be 0 now!

@feeblefakie
Copy link
Contributor

feeblefakie commented Aug 16, 2021

@supl Thank you for the guidance!

I'll share the preliminary benchmarking results in my local environment (that has 4 CPU cores).
I used the same properties file with the following option for smallbank-bench.

--num-accounts 100 --num-threads 4 --duration 10  --ramp-up-time 1

Java SDK (1st time):

TPS: 56.1
Average-Latency(ms): 64.03743315508021
Error-Counts: 79

Java SDK (2nd time):

TPS: 61.7
Average-Latency(ms): 59.79092382495948
Error-Counts: 78

Node SDK (1st time):

TPS: 53.2
Average-Latency(ms): 73.07142857142857
Error-Counts: 25

Node SDK (2nd time):

TPS: 64.9
Average-Latency(ms): 60.003081664098616
Error-Counts: 37

My local environment runs many other processes so it's not a good place for benchmark but
I think they are consistent enough to go :)

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work! Thank you!

I think we can further work on the following things in another PR:

  • Support optional configurations that are consistent with the Java version
  • Support PEM files (for only node version)
  • Update documentation to specify version requirements

@feeblefakie feeblefakie merged commit a05e37e into master Aug 16, 2021
@feeblefakie feeblefakie deleted the DLT-9604 branch August 16, 2021 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants