nandi/gleanpublic Fork 0
d629aca
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add optional Go pprof profiling serverUnverified

Julien Robert committed 2026-05-09T23:58:59+02:00 Browse files
d629aca parent: be4bec9
modified .env.example +3 -0
@@ -24,3 +24,6 @@ GLEAN_EMBED_DIMENSION=2560
2424 GLEAN_LLM_BASE_URL=https://llms.example.com/v1
2525 GLEAN_LLM_API_KEY=API-KEY-001
2626 GLEAN_LLM_MODEL=qwen3.5-35b-a3b
27+# Enable Go pprof profiling server (off by default).
28+# Set to a listen address like :6060 to enable, leave empty to disable.
29+# GLEAN_PPROF_ADDR=:6060
@@ -24,3 +24,6 @@ GLEAN_EMBED_DIMENSION=2560
24 GLEAN_LLM_BASE_URL=https://llms.example.com/v124 GLEAN_LLM_BASE_URL=https://llms.example.com/v1
25 GLEAN_LLM_API_KEY=API-KEY-00125 GLEAN_LLM_API_KEY=API-KEY-001
26 GLEAN_LLM_MODEL=qwen3.5-35b-a3b26 GLEAN_LLM_MODEL=qwen3.5-35b-a3b
27+# Enable Go pprof profiling server (off by default).
28+# Set to a listen address like :6060 to enable, leave empty to disable.
29+# GLEAN_PPROF_ADDR=:6060
modified main.go +16 -0
@@ -6,6 +6,7 @@ import (
66 "fmt"
77 "log/slog"
88 "net/http"
9+ "net/http/pprof"
910 "os"
1011 "os/signal"
1112 "strconv"
@@ -42,6 +43,21 @@ func main() {
4243
4344 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
4445
46+ if pprofAddr := envOr("GLEAN_PPROF_ADDR", ""); pprofAddr != "" {
47+ mux := http.NewServeMux()
48+ mux.HandleFunc("/debug/pprof/", pprof.Index)
49+ mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
50+ mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
51+ mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
52+ mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
53+ go func() {
54+ logger.Info("starting pprof server", "addr", pprofAddr)
55+ if err := http.ListenAndServe(pprofAddr, mux); err != nil {
56+ logger.Error("pprof server error", "error", err)
57+ }
58+ }()
59+ }
60+
4561 vec.Auto()
4662 dbs, err := db.Open(*dbPath)
4763 if err != nil {
@@ -6,6 +6,7 @@ import (
6 "fmt"6 "fmt"
7 "log/slog"7 "log/slog"
8 "net/http"8 "net/http"
9+ "net/http/pprof"
9 "os"10 "os"
10 "os/signal"11 "os/signal"
11 "strconv"12 "strconv"
@@ -42,6 +43,21 @@ func main() {
42 43
43 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))44 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
44 45
46+ if pprofAddr := envOr("GLEAN_PPROF_ADDR", ""); pprofAddr != "" {
47+ mux := http.NewServeMux()
48+ mux.HandleFunc("/debug/pprof/", pprof.Index)
49+ mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
50+ mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
51+ mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
52+ mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
53+ go func() {
54+ logger.Info("starting pprof server", "addr", pprofAddr)
55+ if err := http.ListenAndServe(pprofAddr, mux); err != nil {
56+ logger.Error("pprof server error", "error", err)
57+ }
58+ }()
59+ }
60+
45 vec.Auto()61 vec.Auto()
46 dbs, err := db.Open(*dbPath)62 dbs, err := db.Open(*dbPath)
47 if err != nil {63 if err != nil {
modified readme.md +1 -0
@@ -72,6 +72,7 @@ Then open `http://localhost:8080`.
7272 | `GLEAN_LLM_BASE_URL` | _(empty)_ | LLM API base URL for language detection (see below) |
7373 | `GLEAN_LLM_API_KEY` | _(empty)_ | API key for the LLM endpoint |
7474 | `GLEAN_LLM_MODEL` | `gpt-4o-mini` | LLM model name |
75+| `GLEAN_PPROF_ADDR` | _(empty)_ | Enable pprof profiling server (e.g. `:6060`, off by default) |
7576
7677 For production:
7778
@@ -72,6 +72,7 @@ Then open `http://localhost:8080`.
72 | `GLEAN_LLM_BASE_URL` | _(empty)_ | LLM API base URL for language detection (see below) |72 | `GLEAN_LLM_BASE_URL` | _(empty)_ | LLM API base URL for language detection (see below) |
73 | `GLEAN_LLM_API_KEY` | _(empty)_ | API key for the LLM endpoint |73 | `GLEAN_LLM_API_KEY` | _(empty)_ | API key for the LLM endpoint |
74 | `GLEAN_LLM_MODEL` | `gpt-4o-mini` | LLM model name |74 | `GLEAN_LLM_MODEL` | `gpt-4o-mini` | LLM model name |
75+| `GLEAN_PPROF_ADDR` | _(empty)_ | Enable pprof profiling server (e.g. `:6060`, off by default) |
75 76
76 For production:77 For production:
77 78