Multi threading client application
Hello & Happy new year,
I am using HLF 2.4 with a BC client i.e:
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/pkg/gateway"
sdk, err := fabsdk.New(configBackend)
gwGlobal, err = gateway.Connect(
gateway.WithSDK(sdk),
gateway.WithUser(ClientUserID),
)
The client during initialization connects to BC once (if not
connected). Then, each time a REST request happens a Gin callback
function is called (i.e DoSomething
(c *gin.Context)
). In the DoSomething
function I use :
nw, err := gwGlobal.GetNetwork(channelName)
contract := nw.GetContract(chaincodeName)
resp, err
:= contract.SubmitTransaction(...)
In order to submit a transaction.
As I have seen the Gin framework uses Go routines to run multiple
parallel requests (like multi-threading). My question is:
Do I need multiple BC clients too (i.e more gateway.Connect(...)
using threads) to enhance the performance (i.e requests per
second)?
Thank you for your time,
-- Nikos Karamolegkos R & D engineer at ICS-FORTH Telecommunications and Networks Lab (TNL)
Since you are using Fabric 2.4, I strongly recommend that you use the fabric-gateway client API rather than the fabric-sdk-go API in your client application. This will have the benefit of connecting directly to the embedded gateway service in the 2.4 peer, which will give you performance benefits as well as being easier to use. Going forward, this newer API (for Go, Java & Node) will the only one supported by the Fabric core maintainers.
To answer your question, you don't need to create multiple gateway connections.
Thank you, so I have to base my application to this
example?
Hi Nikos,
Since you are using Fabric 2.4, I strongly recommend that you use the fabric-gateway client API rather than the fabric-sdk-go API in your client application. This will have the benefit of connecting directly to the embedded gateway service in the 2.4 peer, which will give you performance benefits as well as being easier to use. Going forward, this newer API (for Go, Java & Node) will the only one supported by the Fabric core maintainers.
To answer your question, you don't need to create multiple gateway connections.
-- Nikos Karamolegkos R & D engineer at ICS-FORTH Telecommunications and Networks Lab (TNL)