From 90beada459dd853a62d2828ec4655f5e8939f4a4 Mon Sep 17 00:00:00 2001 From: joyz Date: Tue, 22 Jan 2019 22:11:54 +0800 Subject: [PATCH] some modify --- broker/broker.go | 11 +++++++++++ broker/sesson.go | 2 ++ lib/sessions/memprovider.go | 14 -------------- main.go | 10 ++++------ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/broker/broker.go b/broker/broker.go index de1aa73..8470662 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -7,6 +7,7 @@ import ( "fmt" "net" "net/http" + _ "net/http/pprof" "runtime/debug" "sync" "sync/atomic" @@ -153,6 +154,16 @@ func (b *Broker) Start() { //system monitor go StateMonitor() + if b.config.Debug { + startPProf() + } + +} + +func startPProf() { + go func() { + http.ListenAndServe(":10060", nil) + }() } func StateMonitor() { diff --git a/broker/sesson.go b/broker/sesson.go index 59d5c11..dc1e307 100644 --- a/broker/sesson.go +++ b/broker/sesson.go @@ -1,3 +1,5 @@ +/* Copyright (c) 2018, joy.zhou + */ package broker import "github.com/eclipse/paho.mqtt.golang/packets" diff --git a/lib/sessions/memprovider.go b/lib/sessions/memprovider.go index d82d117..b60920a 100644 --- a/lib/sessions/memprovider.go +++ b/lib/sessions/memprovider.go @@ -1,17 +1,3 @@ -// Copyright (c) 2014 The SurgeMQ Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package sessions import ( diff --git a/main.go b/main.go index 0062ff6..70954ee 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ copyright notice and this permission notice appear in all copies. package main import ( - "fmt" + "log" "os" "os/signal" "runtime" @@ -19,19 +19,17 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) config, err := broker.ConfigureConfig(os.Args[1:]) if err != nil { - fmt.Println("configure broker config error: ", err) - return + log.Fatal("configure broker config error: ", err) } b, err := broker.NewBroker(config) if err != nil { - fmt.Println("New Broker error: ", err) - return + log.Fatal("New Broker error: ", err) } b.Start() s := waitForSignal() - fmt.Println("signal received, broker closed.", s) + log.Println("signal received, broker closed.", s) } func waitForSignal() os.Signal {