Skip to content

Commit

Permalink
Add Go pprof support to the orderer
Browse files Browse the repository at this point in the history
Fixes FAB-813. The profiling service is disabled by default, and defaults to
using the 0.0.0.0:6060 interface if enabled.

Change-Id: Ia8abaaacf1a8524444af6c0697c622386c4939d9
Signed-off-by: Bishop Brock <bcbrock@us.ibm.com>
  • Loading branch information
bcbrock committed Nov 2, 2016
1 parent 37b1168 commit a54954d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions orderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ There are currently no other raw ledgers available, although it is anticipated t
To experiment with the orderer service you may build the orderer binary by simply typing `go build` in the `hyperledger/fabric/orderer` directory. You may then invoke the orderer binary with no parameters, or you can override the bind address, port, and backing ledger by setting the environment variables `ORDERER_LISTEN_ADDRESS`, `ORDERER_LISTEN_PORT` and `ORDERER_LEDGER_TYPE` respectively. Presently, only the solo orderer is supported. The deployment and configuration is very stopgap at this point, so expect for this to change noticably in the future.

There are sample clients in the `fabric/orderer/sample_clients` directory. The `broadcast_timestamp` client sends a message containing the timestamp to the `Broadcast` service. The `deliver_stdout` client prints received batches to stdout from the `Deliver` interface. These may both be build simply by typing `go build` in their respective directories. Neither presently supports config, so editing the source manually to adjust address and port is required.

### Profiling

Profiling the orderer service is possible through a standard HTTP interface documented [here](https://golang.org/pkg/net/http/pprof). The profiling service can be configured using the **config.yaml** file, or through environment variables. To enable profiling set `ORDERER_GENERAL_PROFILE_ENABLED=true`, and optionally set `ORDERER_GENERAL_PROFILE_ADDRESS` to the desired network address for the profiling service. The default address is `0.0.0.0:6060` as in the Golang documentation.

Note that failures of the profiling service, either at startup or anytime during the run, will cause the overall orderer service to fail. Therefore it is currently not recommended to enable profiling in production settings.
14 changes: 14 additions & 0 deletions orderer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ type General struct {
ListenAddress string
ListenPort uint16
GenesisMethod string
Profile Profile
}

// Profile contains configuration for Go pprof profiling
type Profile struct {
Enabled bool
Address string
}

// RAMLedger contains config for the RAM ledger
Expand Down Expand Up @@ -99,6 +106,10 @@ var defaults = TopLevel{
ListenAddress: "127.0.0.1",
ListenPort: 5151,
GenesisMethod: "static",
Profile: Profile{
Enabled: false,
Address: "0.0.0.0:6060",
},
},
RAMLedger: RAMLedger{
HistorySize: 10000,
Expand Down Expand Up @@ -150,6 +161,9 @@ func (c *TopLevel) completeInitialization() {
c.General.ListenPort = defaults.General.ListenPort
case c.General.GenesisMethod == "":
c.General.GenesisMethod = defaults.General.GenesisMethod
case c.General.Profile.Enabled && (c.General.Profile.Address == ""):
logger.Infof("Profiling enabled and General.Profile.Address unset, setting to %s", defaults.General.Profile.Address)
c.General.Profile.Address = defaults.General.Profile.Address
case c.FileLedger.Prefix == "":
logger.Infof("FileLedger.Prefix unset, setting to %s", defaults.FileLedger.Prefix)
c.FileLedger.Prefix = defaults.FileLedger.Prefix
Expand Down
13 changes: 13 additions & 0 deletions orderer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"io/ioutil"
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"

Expand All @@ -45,9 +47,20 @@ import (
"google.golang.org/grpc"
)

var logger = logging.MustGetLogger("orderer/main")

func main() {
conf := config.Load()

// Start the profiling service if enabled. The ListenAndServe()
// call does not return unless an error occurs.
if conf.General.Profile.Enabled {
go func() {
logger.Infof("Starting Go pprof profiling service on %s", conf.General.Profile.Address)
panic(fmt.Errorf("Go pprof service failed: %s", http.ListenAndServe(conf.General.Profile.Address, nil)))
}()
}

switch conf.General.OrdererType {
case "solo":
launchSolo(conf)
Expand Down
6 changes: 6 additions & 0 deletions orderer/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ General:
# Genesis method: The method by which to retrieve/generate the genesis block
GenesisMethod: static

# Enable an HTTP service for Go "pprof" profiling as documented at
# https://golang.org/pkg/net/http/pprof
Profile:
Enabled: false
Address: 0.0.0.0:6060

################################################################################
#
# SECTION: RAM Ledger
Expand Down

0 comments on commit a54954d

Please sign in to comment.