From f3849727ca8e83d88bbd6a521601359d41c62357 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 30 Jun 2019 11:35:20 +0200 Subject: Add CLI flag for the concurrency level of libvips --- README.md | 1 + cmd/gopherproxy/main.go | 11 ++++++----- gopherproxy.go | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1898572..2e2cc24 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Arguments: - `-uri=`: The default address to open in the proxy (default: "floodgap.com") - `-robots-file=`: robots.txt file to serve to protect Gopher sites from web crawlers (default: "robots.txt") - `-robots-debug=`: Print output about clients ignoring robots.txt (this includes regular browsers) (default: false) +- `-vips-concurrency=: Concurrency level of libvips (i.e. number of worker threads)` ## Development diff --git a/cmd/gopherproxy/main.go b/cmd/gopherproxy/main.go index e9dea18..e699d14 100644 --- a/cmd/gopherproxy/main.go +++ b/cmd/gopherproxy/main.go @@ -10,15 +10,16 @@ import ( var ( // TODO: Allow config file and environment vars // (opt -> env -> config -> default) - bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to") - robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") - robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") - uri = flag.String("uri", "floodgap.com", ":[port] to proxy to") + bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to") + robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") + robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") + uri = flag.String("uri", "floodgap.com", ":[port] to proxy to") + vipsconcurrency = flag.Int("vips-concurrency", 1, "Concurrency level of libvips") ) func main() { flag.Parse() // Use a config struct - log.Fatal(gopherproxy.ListenAndServe(*bind, *robotsfile, *robotsdebug, *uri)) + log.Fatal(gopherproxy.ListenAndServe(*bind, *robotsfile, *robotsdebug, *vipsconcurrency, *uri)) } diff --git a/gopherproxy.go b/gopherproxy.go index 0ecfa14..0134f88 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -242,7 +242,7 @@ func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { // specified by the request. The robots argument is a pointer to // a robotstxt.RobotsData struct for testing user agents against // a configurable robots.txt file. -func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error { +func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency int, uri string) error { var ( tpl *template.Template robotsdata *robotstxt.RobotsData @@ -329,7 +329,7 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error } vips.Startup(&vips.Config{ - ConcurrencyLevel: 0, + ConcurrencyLevel: vipsconcurrency, }) http.HandleFunc("/", GopherHandler(tpl, robotsdata, AssetHashList{stylehash, jshash, fontwhash, fontw2hash}, robotsdebug, uri)) -- cgit v1.2.3-54-g00ecf