Skip to content

Commit d29d871

Browse files
committed
Polished receiver.
1 parent 4759689 commit d29d871

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

test/performance/roles/receiver/templates/receiver.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Description=Receiver fro NT test
33
After=network.target
44

55
[Service]
6-
ExecStart={{ bin_location }} -ports {{ ports }} -prom-port {{ prom_port }} -profiler {{ pprof_port }}
6+
ExecStart={{ bin_location }} -ports {{ ports }} -promPort {{ prom_port }} -profPort {{ pprof_port }}
77
LimitNOFILE=5000
88
User=nanotube
99
Group=nanotube

test/receiver/receiver.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func main() {
130130
portsStr := flag.String("ports", "", `List of the ports to listen on. Has to be supplied in the from "XXXX YYYY ZZZZ AAAA-BBBB" in quotes.`)
131131
outPrefix := flag.String("prefix", "", "Prefix for the output files.")
132132
outDir := flag.String("outdir", "", "Output directory. Absolute path. Optional.")
133-
profPort := flag.String("profPort", "", "Where should the profiler listen?")
133+
profPort := flag.Int("profPort", 0, "Where should the profiler listen?")
134134
promPort := flag.Int("promPort", 0, "Prometheus port. If unset, Prometheus metrics are not exposed.")
135135

136136
flag.Parse()
@@ -146,15 +146,18 @@ func main() {
146146
go promListen(*promPort, lg)
147147
}
148148

149-
if *profPort != "" {
149+
if *profPort != 0 {
150150
go func() {
151-
lg.Info("profiler server exited", zap.Error(http.ListenAndServe(*profPort, nil)))
151+
lg.Info("profiler server exited", zap.Error(http.ListenAndServe(fmt.Sprintf(":%d", *profPort), nil)))
152152
}()
153153
}
154154

155155
ports := parsePorts(*portsStr, lg)
156-
fs := openFiles(*outDir, *outPrefix, ports, lg)
157-
defer closeFiles(fs, lg)
156+
var fs map[int]*os.File
157+
if *outDir != "" {
158+
fs = openFiles(*outDir, *outPrefix, ports, lg)
159+
defer closeFiles(fs, lg)
160+
}
158161
ls := openPorts(ports, lg)
159162

160163
ms.nOpenPorts.Set(float64(len(ls)))
@@ -165,7 +168,7 @@ func main() {
165168
for _, p := range ports {
166169
portsWG.Add(1)
167170

168-
go listen(ls[p], p, *outDir, stop, &portsWG, fs, ms, lg)
171+
go listen(ls[p], p, stop, &portsWG, fs, ms, lg)
169172
}
170173

171174
sgn := make(chan os.Signal, 1)
@@ -205,7 +208,7 @@ func openPorts(ports []int, lg *zap.Logger) map[int]net.Listener {
205208
return ls
206209
}
207210

208-
func listen(lst net.Listener, prt int, outDir string, stop chan struct{}, portsWG *sync.WaitGroup, fs map[int]*os.File, ms *metrics, lg *zap.Logger) {
211+
func listen(lst net.Listener, prt int, stop chan struct{}, portsWG *sync.WaitGroup, fs map[int]*os.File, ms *metrics, lg *zap.Logger) {
209212
defer portsWG.Done()
210213
var connectionWG sync.WaitGroup
211214
out:
@@ -233,7 +236,7 @@ out:
233236
lg.Fatal("connection close failed", zap.Error(err))
234237
}
235238
}()
236-
if outDir == "" {
239+
if fs == nil {
237240
scanner := bufio.NewScanner(conn)
238241
scanner.Buffer(make([]byte, bufio.MaxScanTokenSize*100), bufio.MaxScanTokenSize)
239242
for scanner.Scan() {

0 commit comments

Comments
 (0)