generated from PenaSide/GolangTemplate
added bench results for 500 and 1000 threads
This commit is contained in:
parent
1e9237a7e8
commit
ab4adbec0e
@ -10,67 +10,86 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//500
|
||||
//PS D:\GoProject\pena_pj\customer\tests\benchmarks> go test -bench=BenchmarkAccountPipe -benchmem -timeout 30m
|
||||
//WAITER OK
|
||||
//goos: windows
|
||||
//goarch: amd64
|
||||
//pkg: penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks
|
||||
//cpu: AMD Ryzen 5 5600H with Radeon Graphics
|
||||
//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
|
||||
//BenchmarkAccountPipe/COUNT_500-12 1 540604425700 ns/op 16440056 B/op 77490 allocs/op
|
||||
//PASS
|
||||
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 130.316s
|
||||
|
||||
//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)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 540.669s
|
||||
|
||||
//1000
|
||||
//PS D:\GoProject\pena_pj\customer\tests\benchmarks> go test -bench=BenchmarkAccountPipe -benchmem -timeout 30m
|
||||
//WAITER OK
|
||||
//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
|
||||
//BenchmarkAccountPipe/COUNT_1000-12 1 1075578283500 ns/op 32757832 B/op 154755 allocs/op
|
||||
//PASS
|
||||
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 1075.632s
|
||||
|
||||
func BenchmarkAccountPipe(b *testing.B) {
|
||||
for _, n := range []int{1000} {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//500
|
||||
//PS D:\GoProject\pena_pj\customer\tests\benchmarks> go test -bench=BenchmarkAccountPipeWithWorker -benchmem
|
||||
//goos: windows
|
||||
//goarch: amd64
|
||||
//pkg: penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks
|
||||
//cpu: AMD Ryzen 5 5600H with Radeon Graphics
|
||||
//BenchmarkAccountPipeWithWorker/COUNT_500-12 1 571782250200 ns/op 16471520 B/op 77575 allocs/op
|
||||
//PASS
|
||||
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 571.868s
|
||||
|
||||
//1000
|
||||
//PS D:\GoProject\pena_pj\customer\tests\benchmarks> go test -bench=BenchmarkAccountPipeWithWorker -benchmem -timeout 30m
|
||||
//goos: windows
|
||||
//goarch: amd64
|
||||
//pkg: penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks
|
||||
//cpu: AMD Ryzen 5 5600H with Radeon Graphics
|
||||
//BenchmarkAccountPipeWithWorker/COUNT_1000-12 1 1076407088000 ns/op 34201936 B/op 156101 allocs/op
|
||||
//PASS
|
||||
//ok penahub.gitlab.yandexcloud.net/pena-services/customer/tests/benchmarks 1076.521s
|
||||
|
||||
func BenchmarkAccountPipeWithWorker(b *testing.B) {
|
||||
for _, n := range []int{500} {
|
||||
for _, n := range []int{10} {
|
||||
b.Run(fmt.Sprintf("COUNT_%d", n), func(b *testing.B) {
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
@ -223,24 +223,26 @@ func main() {
|
||||
watchWorker := workers.NewWatchWorker(collection, logger)
|
||||
go watchWorker.Run(ctx)
|
||||
|
||||
//go func() {
|
||||
// for {
|
||||
// select {
|
||||
// case <-ctx.Done():
|
||||
// fmt.Println("stop update")
|
||||
// return
|
||||
// default:
|
||||
// for i := 0; i < 800; i++ {
|
||||
// _, err := collection.UpdateOne(ctx, bson.M{"userId": fmt.Sprintf("user%d", i)},
|
||||
// bson.M{"$set": bson.M{"field": fmt.Sprintf("value-%d", time.Now().UnixNano())}})
|
||||
// if err != nil {
|
||||
// logger.Error("error update", zap.Error(err))
|
||||
// }
|
||||
// }
|
||||
// time.Sleep(1 * time.Second)
|
||||
// }
|
||||
// }
|
||||
//}()
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
fmt.Println("stop update")
|
||||
return
|
||||
default:
|
||||
for i := 0; i < 800; i++ {
|
||||
fmt.Println("YA WORK OKAY")
|
||||
res, err := collection.UpdateOne(ctx, bson.M{"userId": fmt.Sprintf("user%d", i)},
|
||||
bson.M{"$set": bson.M{"field": fmt.Sprintf("value-%d", time.Now().UnixNano())}})
|
||||
if err != nil {
|
||||
logger.Error("error update", zap.Error(err))
|
||||
}
|
||||
fmt.Println("TOCHNO OKAY", res.ModifiedCount)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
app := initSrv(repo, logger, watchWorker)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user