简体   繁体   中英

Latency of a fabric blockchain

I'm really new in blockchain world and right now i am studying Hyperledger Fabric. I used the fabcar example and i need to calculate latency of a transaction here. I want to start with javascript first and then with other but i'm already in difficult. I thinked to use two timestamp and then subtract them for find the time, but i don't know how to implement it correctly. Here the code for the invoke of a query to the ledger.

    // Submit the specified transaction.
    // createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
    // changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
    var timestamp1 = Number(new Date());
    
    await contract.submitTransaction('createCar', 'CAR25', 'Lamborghini', 'Aventador', 'Green', 'Ciccio');
    console.log('Transaction has been submitted');
    
    var timestamp2 = Number(new Date());
    console.log(timestamp2-timestamp1);

    // Disconnect from the gateway.
    await gateway.disconnect();

} catch (error) {
    console.error(`Failed to submit transaction: ${error}`);
    process.exit(1);
}

What i did make actually sense, it would work? I add also the --waitForEvent to the invoke. I don't find any documentation or examples for implementing something like this. Thanks in advance.

Yes the code should work. But it's only a one-time measurement and proper latency tests should run multiple times and include measures like standard deviation, min, max etc.

For a proper benchmarking tool, checkout Hyperledger Caliper: https://hyperledger.github.io/caliper/v0.4.2/getting-started/#supported-performance-metrics

You can set it up with Hyperledger Fabric and get transaction and read latency (minimum, maximum, average, percentile). It takes care of all the details behind the scenes for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM