Skip to content

Commit

Permalink
PRT-140: portal memory is increasing over time check why what do we c…
Browse files Browse the repository at this point in the history
…ache and forget to release see image addded (#190)

* PRT-140 - support for pprof server (still got err bug)

* PRT-140 - used fiber instead of http

* PRT-140: fixed lint issues

* PRT-140: enabled gofumpt in pprofServer.go

* PRT-140: optional address flag, remove default values
  • Loading branch information
oren-lava authored Dec 25, 2022
1 parent 9e4b3b8 commit c42323e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/lavad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strconv"
"strings"

_ "net/http/pprof"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -97,6 +99,23 @@ func main() {
utils.LavaFormatFatal("failed to read log level flag", err, nil)
}
utils.LoggingLevel(logLevel)

// check if the command includes --pprof-address
pprofAddressFlagUsed := cmd.Flags().Lookup("pprof-address").Changed
if pprofAddressFlagUsed {
// get pprof server ip address (default value: "")
pprofServerAddress, err := cmd.Flags().GetString("pprof-address")
if err != nil {
utils.LavaFormatFatal("failed to read pprof address flag", err, nil)
}

// start pprof HTTP server
err = performance.StartPprofServer(pprofServerAddress)
if err != nil {
return utils.LavaFormatError("failed to start pprof HTTP server", err, nil)
}
}

relayer.PortalServer(ctx, clientCtx, listenAddr, chainID, apiInterface, cmd.Flags())

return nil
Expand Down Expand Up @@ -147,6 +166,7 @@ func main() {
cmdTestClient.MarkFlagRequired(flags.FlagFrom)
cmdTestClient.Flags().Bool("secure", false, "secure sends reliability on every message")
cmdPortalServer.Flags().Bool("secure", false, "secure sends reliability on every message")
cmdPortalServer.Flags().String(performance.PprofAddressFlagName, "", "pprof server address, used for code profiling")
cmdPortalServer.Flags().String(performance.CacheFlagName, "", "address for a cache server to improve performance")
cmdServer.Flags().String(performance.CacheFlagName, "", "address for a cache server to improve performance")
rootCmd.AddCommand(cmdServer)
Expand Down
33 changes: 33 additions & 0 deletions relayer/performance/pprofServer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package performance

import (
"fmt"

"github.com/gofiber/fiber/v2"
fiberpprof "github.com/gofiber/fiber/v2/middleware/pprof"
"github.com/lavanet/lava/utils"
)

const (
PprofAddressFlagName = "pprof-address"
)

func StartPprofServer(addr string) error {
// Set up the Fiber app
app := fiber.New()

// Let the fiber HTTP server use pprof
app.Use(fiberpprof.New())

// Start the HTTP server in a goroutine
go func() {
fmt.Printf("Starting server on %s\n", addr)
if err := app.Listen(addr); err != nil {
fmt.Printf("Error starting pprof HTTP server: %s\n", err)
}
}()

utils.LavaFormatInfo("start pprof HTTP server", &map[string]string{"IPAddress": addr})

return nil
}

0 comments on commit c42323e

Please sign in to comment.