trying vegeta load testing

This commit is contained in:
Yanislav Igonin 2022-05-18 10:23:35 +03:00
parent 50138c2551
commit e7cb6bd176
4 changed files with 20 additions and 7 deletions

7
.gitignore vendored
View File

@ -24,4 +24,9 @@ uploads/
.env .env
*.bin *.bin
tests/metrics.json
tests/plot.html
.DS_Store

View File

@ -49,11 +49,11 @@ func Migrate() {
if !isMigrationInDb { if !isMigrationInDb {
sql := Files.ReadFileText(m) sql := Files.ReadFileText(m)
runMigration(id, name, sql) runMigration(id, name, sql)
log.Println("database migration - " + name + " - online") log.Println("migration - " + name + " - online")
} }
} }
log.Println("database migrations - online") log.Println("migrations - online")
} }
func runMigration(mid int, mname, msql string) { func runMigration(mid int, mname, msql string) {
@ -72,11 +72,11 @@ func runMigration(mid int, mname, msql string) {
func getDbMigrations() MigrationsMap { func getDbMigrations() MigrationsMap {
sql := `SELECT id, name FROM migrations` sql := `SELECT id, name FROM migrations`
rows, err := Pool.Query(context.TODO(), sql) rows, err := Pool.Query(context.TODO(), sql)
if err != nil { if err != nil && isNotNonExistentMigrationsTable(err) {
log.Panicln(err) log.Panicln(err)
} }
if rows.Err() != nil { if rows.Err() != nil && isNotNonExistentMigrationsTable(rows.Err()) {
log.Panicln(rows.Err()) log.Panicln(rows.Err())
} }
@ -93,3 +93,7 @@ func getDbMigrations() MigrationsMap {
return migrationsMap return migrationsMap
} }
func isNotNonExistentMigrationsTable(err error) bool {
return err.Error() != `ERROR: relation "migrations" does not exist (SQLSTATE 42P01)`
}

View File

@ -111,5 +111,5 @@ func seedDb() {
func Seed() { func Seed() {
seedDb() seedDb()
log.Println("mocks - online") log.Println("seeds - online")
} }

View File

@ -1 +1,5 @@
autocannon localhost:3000 echo "GET https://micrach.igonin.dev" | vegeta attack -rate 100 -duration=120s | tee results.bin | vegeta report
# vegeta report -type=json results.bin > metrics.json
cat results.bin | vegeta plot > plot.html
open plot.html
# cat results.bin | vegeta report -type="hist[0,100ms,200ms,300ms]"