Hey, I have a dozen or so custom RPCs in my current Nakama game server, and one of this is just returning a config object immediately back to the requester:
func myRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
buf, err := json.Marshal(cfg.Some.Path)
if err != nil {
return "", fmt.Errorf("failed to marshal response: %w", err)
}
return string(buf), err
}
Looking at my nginx logs, I see this:
[redacted] - - [25/Jul/2023:05:12:49 +0200] "POST /v2/rpc/[redacted]?unwrap=true HTTP/1.1" 200 492 "[redacted]" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0" "[redacted]" 0.135
Explaning:
- The request is taking 135(!)ms
- The resulting json is only 495 bytes on the write (it’s gzip, but the actual raw json itself is ~3.5kb. Not large enough to take 135ms to marshal)
- I can reproduce the average time for this from doing the request via the console explorer too
I would love to hear your suggestions to drill into specifically what’s taking so much time, if there’s any particular tools, etc. My initial thought would be to use something like pprof
, but I’m not sure if there’s alternatives that work better with Nakama.
Thanks for taking the time!