Akshay Sood
Akshay Sood

Reputation: 6776

Hyperledger Fabric nodejs sdk performance issue

I am facing a performance issue while using Hyperledger fabric node.js sdk.

When I issue the invocation request to sdk and consume the response given by the chaincode by using the following code

var proposalResponse = results[0];
            var proposal = results[1];
            let isProposalGood = false;

            if(proposalResponse
                && proposalResponse[0].response
                && proposalResponse[0].response.status === 200){
                    isProposalGood = true;
                    var res = JSON.parse(proposalResponse[0].response.payload.toString());
                            res.event_status = 'VALID'
                            resolve(res);
                }else{
                    reject(createErrorResponse(proposalResponse[0].message,500))
                    return
                }

The api responds within 50ms as you can see the screenshot below: enter image description here

But, when I wait for orderer to confirm the transaction by using the following code:

if (code === 'VALID'){
                            //get payload from proposal response
                            var res = JSON.parse(proposalResponse[0].response.payload.toString());
                            res.event_status = 'VALID'
                            resolve(res);
                        }else{
                            var return_status = createErrorResponse("Transaction was not valid", 500);
                            return_status.tx_id = transaction_id_string
                            reject(return_status)
                            return
                        }

It takes nearby 2500ms to response as you can see the screenshot of postman below:

enter image description here

Correct me if I am wrong

I know it takes time because the orderer confirms the transaction and commits into the ledger. But don't you think we should proceed only if the orderer agrees to transaction and commits into the ledger. If yes, then it will take 2.5 seconds to response (network is running on docker in local machine & sdk on same machine) which is a performance issue.

What happen if data is written into the chaincode and after that orderers deny to write the transaction into the ledger?

Any help would be appreciated

Upvotes: 1

Views: 594

Answers (2)

Akshay Sood
Akshay Sood

Reputation: 6776

I found another reason for this delay.

The batchtimeout variable in configtx.yaml is set to 2 seconds. So it will do its processing and then wait for 2 seconds and then cut a block. So for write operation it takes approximately 2.5 seconds.

Upvotes: 0

Maddy Blacklisted
Maddy Blacklisted

Reputation: 1190

the orderer confirms the transaction and commits into the ledger.

The task for the Ordering service (As the name suggests) is only to order the received endorsed transactions chronologically by channel and then deliver them to all the peers in the channel. Orderers don't actually commit the transactions into the ledger.

The Committer Peers do. And committing is a time-taking process since all the peers validate all the transactions within the block to ensure endorsement policy is fulfilled and to ensure that there have been no changes to ledger state for read set variables since the read set was generated by the transaction execution. Transactions in the block are tagged as being valid or invalid. Then Each peer appends the block to the channel’s chain, and for each valid transaction the write sets are committed to current state database. An event is emitted, to notify the client application that the transaction (invocation) has been immutably appended to the chain, as well as notification of whether the transaction was validated or invalidated.

So after knowing all these details in the Transaction Flow, It should be noted that the client application shouldn't wait for the response received by the orderer. Instead it should just request the orderer to deliver the endorsed transactions and the application should be subscribed to the events emitted by the peers so that it should know or be notified that the transactions are actually immutably committed in the channel's chain.

You can have further help regarding event subscription in the Fabric Node SDK docs.

What happen if data is written into the chaincode and after that orderers deny to write the transaction into the ledger?

This is simply impossible as data is appended to the chain only when the transaction is validated through proper endorsements from the endorser peers (specified by the endorsement policy) and then finally delivered to the committer peers to append the new values in the chain and update the world state. Data is only written in the chain after it passes all the validations and hence an orderer can never deny for the changes made in the data.

Upvotes: 1

Related Questions