Skip to content

Commit

Permalink
Add READ_BUFFER_SIZE, CONCURRENCY,DISABLE_KEEPALIVE to ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
n0vad3v committed Oct 17, 2023
1 parent 0b0e5b1 commit 976ef38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,13 @@ services:
restart: always
environment:
- MALLOC_ARENA_MAX=1
# - LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
# - LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.5.6
volumes:
- ./path/to/pics:/opt/pics
- ./path/to/exhaust:/opt/exhaust
- ./path/to/metadata:/opt/metadata
- ./config.json:/etc/config.json
ports:
- 127.0.0.1:3333:3333
deploy:
resources:
limits:
memory: 400M
memswap_limit: 400M
```

You can refer to [Docker | WebP Server Documentation](https://docs.webp.sh/usage/docker/) for more info, such as custom config, AVIF support etc.
Expand All @@ -96,7 +89,7 @@ You can refer to [Docker | WebP Server Documentation](https://docs.webp.sh/usage

If you'd like to use with binary, please consult to [Use with Binary(Advanced) | WebP Server Documentation](https://docs.webp.sh/usage/usage-with-binary/)

>spoiler alert: you may encounter issues with `glibc` and some dependency libraries.
> spoiler alert: you may encounter issues with `glibc` and some dependency libraries.

For `supervisor` or detailed Nginx configuration, please read our documentation at [https://docs.webp.sh/](https://docs.webp.sh/)

Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
ProxyMode bool
Prefetch bool
Config jsonFile
Version = "0.9.11"
Version = "0.9.12"
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
RemoteRaw = "./remote-raw"
Metadata = "./metadata"
Expand All @@ -86,9 +86,9 @@ type jsonFile struct {

func init() {
flag.StringVar(&ConfigPath, "config", "config.json", "/path/to/config.json. (Default: ./config.json)")
flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert image to webp")
flag.BoolVar(&Prefetch, "prefetch", false, "Prefetch and convert image to WebP format.")
flag.IntVar(&Jobs, "jobs", runtime.NumCPU(), "Prefetch thread, default is all.")
flag.BoolVar(&DumpConfig, "dump-config", false, "Print sample config.json")
flag.BoolVar(&DumpConfig, "dump-config", false, "Print sample config.json.")
flag.BoolVar(&DumpSystemd, "dump-systemd", false, "Print sample systemd service file.")
flag.BoolVar(&ShowVersion, "V", false, "Show version information.")
}
Expand Down
8 changes: 8 additions & 0 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,11 @@ func HashFile(filepath string) string {
buf, _ := os.ReadFile(filepath)
return fmt.Sprintf("%x", xxhash.Sum64(buf))
}

func GetEnv(key string, defaultVal ...string) string {
value := os.Getenv(key)
if value == "" && len(defaultVal) > 0 {
return defaultVal[0]
}
return value
}
15 changes: 15 additions & 0 deletions webp-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"webp_server_go/config"
"webp_server_go/encoder"
"webp_server_go/handler"
"webp_server_go/helper"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/etag"
Expand All @@ -16,11 +18,24 @@ import (
log "github.com/sirupsen/logrus"
)

var (
ReadBufferSizeStr = helper.GetEnv("READ_BUFFER_SIZE", "4096") // Default: 4096
ReadBufferSize, _ = strconv.Atoi(ReadBufferSizeStr)
ConcurrencyStr = helper.GetEnv("CONCURRENCY", "262144") // Default: 256 * 1024
Concurrency, _ = strconv.Atoi(ConcurrencyStr)
DisableKeepaliveStr = helper.GetEnv("DISABLE_KEEPALIVE", "false") // Default: false
DisableKeepalive, _ = strconv.ParseBool(DisableKeepaliveStr)
)

// https://docs.gofiber.io/api/fiber
var app = fiber.New(fiber.Config{
ServerHeader: "WebP Server Go",
AppName: "WebP Server Go",
DisableStartupMessage: true,
ProxyHeader: "X-Real-IP",
ReadBufferSize: ReadBufferSize, // per-connection buffer size for requests' reading. This also limits the maximum header size. Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies).
Concurrency: Concurrency, // Maximum number of concurrent connections.
DisableKeepalive: DisableKeepalive, // Disable keep-alive connections, the server will close incoming connections after sending the first response to the client
})

func setupLogger() {
Expand Down

0 comments on commit 976ef38

Please sign in to comment.