hyperledger / caliper

A blockchain benchmark framework to measure performance of multiple blockchain solutions https://wiki.hyperledger.org/display/caliper
https://hyperledger.github.io/caliper/
Apache License 2.0
642 stars 403 forks source link

Interface on use of releaseContext and actual use differ, plus use of getContext/releaseContext doesn't seem correct within a worker #1590

Open davidkel opened 1 month ago

davidkel commented 1 month ago

In the code and documentation the connector interface for the releaseContext method shows it takes no parameters, yet in the the code we see the worker actually does this

            await this.connector.releaseContext(context);

Also note that a context is both retrieved and release at 2 stages not 1.

  1. In prepareTest of the worker to pass something into the workload module at initialisation time, but is released after that
  2. in executeRound of a worker

Now the concept as the context is a bit vague but it is a way to prepare a connector for execution of a round and this is exactly what the fabric connector does by creating connections then dropping them after the round has finished which makes sense for 2. What doesn't make sense is it's use in 1

If this is about providing a context to the workload module then why is is released at the end of prepareTest ? It would mean that the context provided to the workload module is now not valid as the context created at prepareTest doesn't have to the be same as the context created when the round is executed. In the case of fabric although it won't be the same object, it will be an object that would equate to the one provided to the workload module but contains no useful information really so is irrelevant.

For ethereum, it never does anything in releaseContext, but creates a new context object which provides a lot of information and this may or may not equate to the same object between prepareTest and executeRound.

Given that prepareTest is always done before executeRound, surely it makes sense for the context to be obtained during or before prepareTest and only released after executeRound ? that should provide performance improvements to caliper and the connectors as it means that doing a load or work twice for no reason will be eliminated. It would also mean that the context provided to the workload is actually meaningful.