hyperledger / hyperledger/fabric
CouchDB queries are extremely slow after many queries are made
- Dominant language
- Go
- Stars
- 16.7k
- Forks
- 9.1k
- Avg merge
- 5h 38m
- Merged PRs (30d)
- 26
Description
### Description
We have a chaincode which mints a great amount of _tokens_.
These tokens contain additional information which sometimes we need to reconstruct.
There might be some 100.000 tokens. Each of them having 100 couch keys associated to it
Our operation consists in reading these 100.000 tokens, and each call iterates over 100 keys with a grand total of 10.000.000 queries to couchdb in this case.
After one hour of queries everything's smooth with 200-400ms per TOKEN
After that the situation degrades quickly and we are left with one token request per minute or worse every two minutes: which abruptly ends in a DEADLINE_EXCEEDED error.
### Steps to reproduce
1. make 100.000 requests to a chaincode
2. wait.
to help this is the chaincode function we're calling 100.000 times
```go
func (c *xxxxx) Token(ctx contractapi.TransactionContextInterface, tokenId string) (string, error) {
token, err := GetTokenData(ctx, tokenId)
if err != nil {
return "", err
}
tokenxxxxx := xxxxxx
iterator, err := ctx.GetStub().GetStateByPartialCompositeKey(PrefixTokenxxxxxx, []string{tokenId})
if err != nil {
return "", fmt.Errorf("error creating asset chaincode: %v", err)
}
for iterator.HasNext() {
queryResponse, err := iterator.Next()
if err != nil {
return "", err
}
// Recupero il tokenId
_, compositeKeyParts, err := ctx.GetStub().SplitCompositeKey(queryResponse.Key)
if err != nil {
return "", err
}
/// OTHER CODE REDACTED BUT OF NO CONCERN
}
_ = iterator.Close()
resultByte, err := json.Marshal(tokenWithxxxxxxx)
return string(resultByte), nil
}
```
Contributor guide
Assessment
This issue has not been assessed yet.