mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
fix: skip set ulimit on windows
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/hrp"
|
"github.com/httprunner/hrp"
|
||||||
@@ -22,8 +19,8 @@ var boomCmd = &cobra.Command{
|
|||||||
$ hrp boom examples/ # run testcases in specified folder`,
|
$ hrp boom examples/ # run testcases in specified folder`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
setUlimit()
|
boomer.SetUlimit(10240) // ulimit -n 10240
|
||||||
setLogLevel("WARN") // disable info logs for load testing
|
setLogLevel("WARN") // disable info logs for load testing
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var paths []hrp.ITestCase
|
var paths []hrp.ITestCase
|
||||||
@@ -71,31 +68,3 @@ func init() {
|
|||||||
boomCmd.Flags().StringVar(&prometheusPushgatewayURL, "prometheus-gateway", "", "Prometheus Pushgateway url.")
|
boomCmd.Flags().StringVar(&prometheusPushgatewayURL, "prometheus-gateway", "", "Prometheus Pushgateway url.")
|
||||||
boomCmd.Flags().BoolVar(&disableConsoleOutput, "disable-console-output", false, "Disable console output.")
|
boomCmd.Flags().BoolVar(&disableConsoleOutput, "disable-console-output", false, "Disable console output.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// set resource limit
|
|
||||||
// ulimit -n 10240
|
|
||||||
func setUlimit() {
|
|
||||||
log.Info().Str("runtime.GOOS", runtime.GOOS).Msg("check GOOS")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
log.Warn().Msg("windows does not support setting ulimit")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var rLimit syscall.Rlimit
|
|
||||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("get ulimit failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Info().Uint64("limit", rLimit.Cur).Msg("get current ulimit")
|
|
||||||
if rLimit.Cur >= 10240 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rLimit.Cur = 10240
|
|
||||||
log.Info().Uint64("limit", rLimit.Cur).Msg("set current ulimit")
|
|
||||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("set ulimit failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
32
internal/boomer/ulimit.go
Normal file
32
internal/boomer/ulimit.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package boomer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// set resource limit
|
||||||
|
// ulimit -n 10240
|
||||||
|
func SetUlimit(limit uint64) {
|
||||||
|
var rLimit syscall.Rlimit
|
||||||
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("get ulimit failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Info().Uint64("limit", rLimit.Cur).Msg("get current ulimit")
|
||||||
|
if rLimit.Cur >= limit {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rLimit.Cur = limit
|
||||||
|
log.Info().Uint64("limit", rLimit.Cur).Msg("set current ulimit")
|
||||||
|
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("set ulimit failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
12
internal/boomer/ulimit_windows.go
Normal file
12
internal/boomer/ulimit_windows.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package boomer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// set resource limit
|
||||||
|
func SetUlimit(limit uint64) {
|
||||||
|
log.Warn().Msg("windows does not support setting ulimit")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user