When user receives an Verifiable Credential(VC) from IDP, user can submit the VC to the Redbelly Network to gain write permission to the network. However, when user submit this initial request, user MUST have RBNT to submit the transaction. Therefore, this service, allows IDP to distribute the initial RBNT to user
This service has /distribute?address=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
to distribute 1 RBNT to
the given address
The team has developed this solution, when this API is called in lower rate, everything work perfectly However, when it in high load, example 100 requests per seconds, the application start to fail.
Initially, the team has the following loader seq/main.go
with the following code
func main() {
for i := 0; i < 100; i++ {
resp, err := http.Get("http://localhost:8080/distribute?address=0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
if err != nil {
log.Fatalln(err)
}
log.Printf("response %v", resp)
}
}
This work perfectly with no error
However, the read world situation is concurrent request parallel/main.go
func main() {
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
resp, err := http.Get("http://localhost:8080/distribute?address=0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
if err != nil {
log.Fatalln(err)
}
log.Printf("response %v", resp)
}()
}
wg.Wait()
}
- Improve the API can handle 100 requests per seconds without fail
- The service MUST be able to deliver the coin
- No database, can use internal map or any storage for demo purpose
- Start a local blockchain using hardhat
- Start the service
- Make a lot of requests
Each step run in it own console window
cd node
npm install
npx hardhat node
go run main.go
go run parallel/main.go