From c8a5f8a68f28e8d910c648d52125f8d28b400b25 Mon Sep 17 00:00:00 2001 From: unwox Date: Fri, 23 Aug 2024 21:34:11 +0600 Subject: allow to change number of workers with -n flag --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index f4480f6..4cbc7c9 100644 --- a/main.go +++ b/main.go @@ -9,15 +9,19 @@ import ( "log" "net/http" "os" + "runtime" "strings" "time" ) func main() { - if len(os.Args) != 2 { + wrksNum := flag.Int("n", runtime.NumCPU(), "Number of HTTP-workers to start") + flag.Parse() + + if flag.NArg() != 1 { printUsage() } - luaExe := os.Args[1] + luaExe := flag.Arg(0) mustExist(luaExe) httpClient := &http.Client{} @@ -135,7 +139,7 @@ func main() { module["http"] = httpModule // start workers - for i := 0; i < 1; i++ { + for i := 0; i < *wrksNum; i++ { wrk := NewWorker() wrks = append(wrks, wrk) go func () { -- cgit v1.2.3