Skip to content

Commit a54954d

Browse files
author
bcbrock
committed
Add Go pprof support to the orderer
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 <[email protected]>
1 parent 37b1168 commit a54954d

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

orderer/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ There are currently no other raw ledgers available, although it is anticipated t
2929
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.
3030

3131
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.
32+
33+
### Profiling
34+
35+
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.
36+
37+
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.

orderer/config/config.go

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ type General struct {
4848
ListenAddress string
4949
ListenPort uint16
5050
GenesisMethod string
51+
Profile Profile
52+
}
53+
54+
// Profile contains configuration for Go pprof profiling
55+
type Profile struct {
56+
Enabled bool
57+
Address string
5158
}
5259

5360
// RAMLedger contains config for the RAM ledger
@@ -99,6 +106,10 @@ var defaults = TopLevel{
99106
ListenAddress: "127.0.0.1",
100107
ListenPort: 5151,
101108
GenesisMethod: "static",
109+
Profile: Profile{
110+
Enabled: false,
111+
Address: "0.0.0.0:6060",
112+
},
102113
},
103114
RAMLedger: RAMLedger{
104115
HistorySize: 10000,
@@ -150,6 +161,9 @@ func (c *TopLevel) completeInitialization() {
150161
c.General.ListenPort = defaults.General.ListenPort
151162
case c.General.GenesisMethod == "":
152163
c.General.GenesisMethod = defaults.General.GenesisMethod
164+
case c.General.Profile.Enabled && (c.General.Profile.Address == ""):
165+
logger.Infof("Profiling enabled and General.Profile.Address unset, setting to %s", defaults.General.Profile.Address)
166+
c.General.Profile.Address = defaults.General.Profile.Address
153167
case c.FileLedger.Prefix == "":
154168
logger.Infof("FileLedger.Prefix unset, setting to %s", defaults.FileLedger.Prefix)
155169
c.FileLedger.Prefix = defaults.FileLedger.Prefix

orderer/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"io/ioutil"
2323
"log"
2424
"net"
25+
"net/http"
26+
_ "net/http/pprof"
2527
"os"
2628
"os/signal"
2729

@@ -45,9 +47,20 @@ import (
4547
"google.golang.org/grpc"
4648
)
4749

50+
var logger = logging.MustGetLogger("orderer/main")
51+
4852
func main() {
4953
conf := config.Load()
5054

55+
// Start the profiling service if enabled. The ListenAndServe()
56+
// call does not return unless an error occurs.
57+
if conf.General.Profile.Enabled {
58+
go func() {
59+
logger.Infof("Starting Go pprof profiling service on %s", conf.General.Profile.Address)
60+
panic(fmt.Errorf("Go pprof service failed: %s", http.ListenAndServe(conf.General.Profile.Address, nil)))
61+
}()
62+
}
63+
5164
switch conf.General.OrdererType {
5265
case "solo":
5366
launchSolo(conf)

orderer/orderer.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ General:
4141
# Genesis method: The method by which to retrieve/generate the genesis block
4242
GenesisMethod: static
4343

44+
# Enable an HTTP service for Go "pprof" profiling as documented at
45+
# https://golang.org/pkg/net/http/pprof
46+
Profile:
47+
Enabled: false
48+
Address: 0.0.0.0:6060
49+
4450
################################################################################
4551
#
4652
# SECTION: RAM Ledger

0 commit comments

Comments
 (0)