# Profiling/Debugging Custom RPCs

**URL:** <https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123>\
**Category:** Runtime Framework\
**Tags:** golang, server-framework\
**Created:** [July 25, 2023, 4:34am UTC](https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123 "2023-07-25T04:34:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnowls](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/jnowls/32/1737_2.png) [@jnowls](https://forum.heroiclabs.com/u/jnowls)\
**Post date:** [July 25, 2023, 4:34am UTC](https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123/1 "2023-07-25T04:34:52Z")

</div>

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:

```go
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:

```auto
[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!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [July 25, 2023, 1:33pm UTC](https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123/2 "2023-07-25T13:33:50Z")

</div>

Hello @jnowls,

Nakama exposes pprof endpoints in the console API (default port 7351) at `/debug/pprof/` (see all the endpoints [here](https://github.com/heroiclabs/nakama/blob/v3.26.0/server/console.go#L297).

You can use basic auth with the console admin credentials to access these endpoints.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Eatos](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/eatos/32/1656_2.png) [@Eatos](https://forum.heroiclabs.com/u/Eatos)\
**Post date:** [July 26, 2023, 12:07am UTC](https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123/3 "2023-07-26T00:07:31Z")

</div>

@sesposito is there a guide or some example how it could be accessed.  
I have tried normally to access it at : [http://127.0.0.1:7351/debug/pprof](http://127.0.0.1:7351/debug/pprof) to see it and previously having logged to console as admin but no info is shown o.O

---

<div class="post-metadata">

**Author:** ![flavio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/flavio/32/2161_2.png) [@flavio](https://forum.heroiclabs.com/u/flavio)\
**Post date:** [July 26, 2023, 12:24pm UTC](https://forum.heroiclabs.com/t/profiling-debugging-custom-rpcs/4123/4 "2023-07-26T12:24:54Z")

</div>

Hello @Eatos,

You would access the snapshot using curl and then pass it to `go tool pprof`.

`curl -u '$USER:$PASSWORD' 'http://127.0.0.1:7351/debug/pprof/$PROFILE > $PROFILE.out' && go tool pprof $PROFILE.out`

For more details about pprof, please check the [package docs](https://pkg.go.dev/net/http/pprof).
