Besides the HTTP standard approach and the workaround that Shawn mentioned, 
a couple other options include:

* installing the gops agent [1] in the binary and using the gops CLI when 
SSHed onto the machine
* adding your own hook (via CLI, custom HTTP endpoint, on a timer, etc.) to 
directly capture profiles using runtime/pprof [2] or the simpler 
lightweight wrapper in pkg/profile [3] 

You're right that profiling the live app will give you the most informative 
results, but if you're new to profiling, it's worth running locally first 
to gain familiarity and comfort with the tooling, where you can quickly 
make changes to your application to see how the profile results change.

[1] https://github.com/google/gops
[2] https://golang.org/pkg/runtime/pprof/
[3] https://github.com/pkg/profile

On Thursday, December 22, 2016 at 7:14:04 PM UTC-8, 569...@gmail.com wrote:
>
> Hello,
>
> I have a webserver application written in Golang that runs on a dedicated 
> server. It serves a popular website and uses almost 100% CPU and 100GB of 
> memory. It's in production but I'd like to profile it as it is: live. It's 
> on a remote webserver, which I have access too via HTTP and SSH (i.e. 
> non-local.)
>
> I'd like to profile the webserver so that I can optimize both CPU and 
> memory usage. I tried adding "import _ net/http/pprof" but I am unable to 
> access any of the reports.
>
> The website is served using the "github.com/facebookgo/grace/gracehttp" 
> package to allow for graceful restarts, as follows:
>
>  serverHTTPS := &http.Server{
>  Addr:           constants.URL + `:443`,
>  Handler:        hdl,
>  ReadTimeout:    30 * time.Second, // how long a file can be uploaded for 
> before it timesout
>  WriteTimeout:   60 * time.Minute, // how long a file can be downloaded 
> for before it timesout
>  MaxHeaderBytes: 1024 * 1024, // 1 MB
>  TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
>  TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler
> )), // disable http2 due to bugs
>  }
>  serverHTTP := &http.Server{
>  Addr:           constants.URL + `:80`,
>  Handler:        redirhdl{},
>  ReadTimeout:    10 * time.Second, // how long a file can be uploaded for 
> before it timesout
>  WriteTimeout:   10 * time.Minute, // how long a file can be downloaded 
> for before it timesout
>  MaxHeaderBytes: 512 * 1024, // 512 KB
>  }
>  log.Fatal(gracehttp.Serve(serverHTTPS, serverHTTP))
>
> The "hdl" struct has a ServeHTTP method which parses the URL to decide 
> which page to serve.
>
> If I try to visit the site with /debug/pprof all I get is my standard 404 
> page not found message.
>
> I tried catching the /debug/pprof path from ServeHTTP and just returning 
> this immediately, but that doesn't work either, it just gives a blank page.
>
> Any ideas how I can profile this live webserver?
>
> Thanks,
> Alasdair
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to