customer/tests/benchmarks/sse_watcher_test.go

106 lines
3.6 KiB
Go
Raw Normal View History

package benchmarks
import (
"bufio"
"fmt"
"github.com/stretchr/testify/require"
"net/http"
"sync"
"testing"
"time"
)
2024-07-21 11:26:28 +00:00
//goos: windows
//goarch: amd64
//pkg: penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks
//cpu: AMD Ryzen 5 5600H with Radeon Graphics
2024-07-21 11:32:57 +00:00
//BenchmarkAccountPipe/COUNT_10-12 1 18041336300 ns/op 13851296 B/op 161900 allocs/op
//BenchmarkAccountPipe/COUNT_20-12 1 18034383800 ns/op 14816216 B/op 173328 allocs/op
//BenchmarkAccountPipe/COUNT_30-12 1 21409782300 ns/op 17761944 B/op 211032 allocs/op
//BenchmarkAccountPipe/COUNT_40-12 1 18021639700 ns/op 19411096 B/op 231789 allocs/op
//BenchmarkAccountPipe/COUNT_50-12 1 19064359600 ns/op 20592840 B/op 245590 allocs/op
2024-07-21 11:26:28 +00:00
//PASS
2024-07-21 11:32:57 +00:00
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 130.316s
2024-07-21 11:26:28 +00:00
2024-07-21 20:03:14 +00:00
//func BenchmarkAccountPipe(b *testing.B) {
// for _, n := range []int{100} {
// b.Run(fmt.Sprintf("COUNT_%d", n), func(b *testing.B) {
// var wg sync.WaitGroup
// for i := 0; i < b.N; i++ {
// wg.Add(n)
// for j := 0; j < n; j++ {
// go func(j int) {
// defer wg.Done()
// userID := fmt.Sprintf("user%d", j)
// //fmt.Println(userID)
// resp, err := http.Get(fmt.Sprintf("http://localhost:3000/account-pipe/%s", userID))
// require.NoError(b, err)
// defer resp.Body.Close()
// scanner := bufio.NewScanner(resp.Body)
// count := 0
// for scanner.Scan() {
// if count == 25 {
// break
// }
// count++
// //line := scanner.Text()
// //fmt.Println("Received:", line)
// }
// time.Sleep(2 * time.Second)
// }(j)
// time.Sleep(time.Second)
// }
// wg.Wait()
// fmt.Println("WAITER OK")
// time.Sleep(1 * time.Second)
// }
// })
// }
//}
2024-07-21 10:33:17 +00:00
2024-07-21 11:26:28 +00:00
//goos: windows
//goarch: amd64
//pkg: penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks
//cpu: AMD Ryzen 5 5600H with Radeon Graphics
//BenchmarkAccountPipeWithWorker/COUNT_10-12 1 68031591200 ns/op 45935456 B/op 545790 allocs/op
//BenchmarkAccountPipeWithWorker/COUNT_20-12 1 68020876100 ns/op 46873480 B/op 557504 allocs/op
//BenchmarkAccountPipeWithWorker/COUNT_30-12 1 68048437700 ns/op 47456704 B/op 562015 allocs/op
//BenchmarkAccountPipeWithWorker/COUNT_40-12 1 68025191100 ns/op 47200848 B/op 556732 allocs/op
//BenchmarkAccountPipeWithWorker/COUNT_50-12 1 68030922700 ns/op 48254768 B/op 567123 allocs/op
//PASS
2024-07-21 11:33:18 +00:00
func BenchmarkAccountPipeWithWorker(b *testing.B) {
2024-07-21 20:03:14 +00:00
for _, n := range []int{500} {
2024-07-21 11:33:18 +00:00
b.Run(fmt.Sprintf("COUNT_%d", n), func(b *testing.B) {
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
wg.Add(n)
for j := 0; j < n; j++ {
go func(j int) {
defer wg.Done()
userID := fmt.Sprintf("user%d", j)
//fmt.Println(userID)
resp, err := http.Get(fmt.Sprintf("http://localhost:3000/account-pipe-wc/%s", userID))
require.NoError(b, err)
defer resp.Body.Close()
scanner := bufio.NewScanner(resp.Body)
count := 0
for scanner.Scan() {
if count == 25 {
break
}
count++
//line := scanner.Text()
//fmt.Println("Received:", line)
}
time.Sleep(2 * time.Second)
}(j)
2024-07-21 20:03:14 +00:00
time.Sleep(time.Second)
2024-07-21 11:33:18 +00:00
}
wg.Wait()
time.Sleep(1 * time.Second)
}
})
}
}