You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now we are sequentially calling each query in the dashboard call. Would be nice to take go to its advantage and run all queries concurrently since they are independent from each other.
The text was updated successfully, but these errors were encountered:
I tried taking a stab at this, by using channels and waitgroups, don't know if that is right. But I regressed:
Before:
[Wed Jul 21 2021 21:22:34 GMT-0700 (Pacific Daylight Time)] INFO Requests: 1341, requests per second: 269, mean latency: 33 ms
[Wed Jul 21 2021 21:22:39 GMT-0700 (Pacific Daylight Time)] INFO Requests: 2839, requests per second: 299, mean latency: 33 ms
[Wed Jul 21 2021 21:22:44 GMT-0700 (Pacific Daylight Time)] INFO Requests: 4343, requests per second: 301, mean latency: 34 ms
After:
[Wed Jul 21 2021 21:24:11 GMT-0700 (Pacific Daylight Time)] INFO Requests: 1345, requests per second: 269, mean latency: 16.4 ms
[Wed Jul 21 2021 21:24:16 GMT-0700 (Pacific Daylight Time)] INFO Requests: 2844, requests per second: 300, mean latency: 16.6 ms
[Wed Jul 21 2021 21:24:21 GMT-0700 (Pacific Daylight Time)] INFO Requests: 4343, requests per second: 300, mean latency: 16.8 ms
The way I did it was, maybe the speed latency increase was due to channel creation and close are expensive:
clients := make(chan []client)
languages := make(chan []client)
operatingSystems := make(chan []client)
versions := make(chan []client)
var waitGroup sync.WaitGroup
waitGroup.Add(4)
go func() {
data, err := clientQuery(a.db, topClientsQuery, whereArgs...)
if err != nil {
fmt.Println(err)
}
clients <- data
defer waitGroup.Done()
}()
go func() {
data, err := clientQuery(a.db, topLanguageQuery, whereArgs...)
if err != nil {
fmt.Println(err)
}
languages <- data
defer waitGroup.Done()
}()
go func() {
data, err := clientQuery(a.db, topOsQuery, whereArgs...)
if err != nil {
fmt.Println(err)
}
operatingSystems <- data
defer waitGroup.Done()
}()
go func() {
// When the filter has a name, we don't want to include that in the json response.
if nameCountInQuery == 1 {
data, err := clientQuery(a.db, topVersionQuery, whereArgs...)
if err != nil {
fmt.Println(err)
}
versions <- data
}
defer waitGroup.Done()
}()
go func() {
waitGroup.Wait()
close(clients)
close(languages)
close(operatingSystems)
close(versions)
}()
Right now we are sequentially calling each query in the dashboard call. Would be nice to take go to its advantage and run all queries concurrently since they are independent from each other.
The text was updated successfully, but these errors were encountered: