Clarify: can external chaincode be replicated?
Looking at Configuring a peer to process external chaincode and Writing chaincode to run as an external service, it looks like it should be possible for a chaincode to be run on multiple machines and for a peer to connect to those multiple instances (with some form of load balancing), by making multiple calls to shim.ChaincodeServer and defining multiple external builders with
externalBuilders:
- name: myexternal1
path: <fully qualified path to #1 on the peer's env>
- name: myexternal2
path: <fully qualified path to #2 on the peer's env>
And so on. Is this in fact possible?
Hi @jkopczyn
There was some good discussion on load-balancing chaincode on the Discord #fabric-kubernetes "LOAD BALANCING CHAINCODE" thread. In general, the consensus and recommendation was to distribute gRPC messages across load-balanced peers, using the Gateway client.
Load balancing individual gRPC messages at the peer<->CCaaS protocol is an open question, and would definitely be possible with the introduction of a mid-stream protocol router, such as Linkerd. There are probably some mechanics in the CC handshake protocol that would need to be investigated to set this up with a reliable, correct (state-wise) mechanism.
Not sure if this link works but see the notes over at discord #fabric-kubernetes LOAD BALANCING CHAINCODE.
To add some more detail on the mechanisms:
For a given chaincode package, the peer will ask each builder in turn if it can handle the package. The first one that replies 'yes' is given the chance to build/run this chaincode. So if myexternal1 says yes, myexternal2 will never be invoked.
It would, in theory, be possible to create a builder such that myexternal1 would say yes to packages A-M, and myexternal2 would say yes to N-Z.
It's important to know that the connection between peer and chaincode is long-running. It's not created each time a transaction is invoked. Therefore any load-balancing can be tricky as @jkneubuh says.