Skip to content

Commit

Permalink
fix CPU high usage on docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanyu committed Apr 4, 2018
1 parent 381ffd9 commit 6d87af2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
3 changes: 1 addition & 2 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http/httputil"
"log"
"net"
"context"
"time"
"io/ioutil"
"context"
)

type handle struct {
Expand All @@ -21,7 +21,6 @@ func (this *handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Fatalln(err)
}

dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
Expand Down
24 changes: 4 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package main

import (
"log"
"net/http"
"bufio"
"os"
"strings"
"log"
)

var srv http.Server
Expand All @@ -15,33 +12,20 @@ func StartServer(bind string, remote string) {
h := &handle{reverseProxy: remote}
srv.Addr = bind
srv.Handler = h

go func() {
//go func() {
if err := srv.ListenAndServe(); err != nil {
log.Fatalln("ListenAndServe: ", err)
}
}()
//}()
}

func StopServer() {
if err := srv.Close() ; err != nil {
if err := srv.Shutdown(nil) ; err != nil {
log.Println(err)
}
}

func main() {
cmd := parseCmd()
StartServer(cmd.bind, cmd.remote)
reader := bufio.NewReader(os.Stdin)
for {
str, err := reader.ReadString('\n')
if err != nil {
log.Println(err)
}
if strings.TrimSpace(str) == "stop" {
log.Println("will stop server")
StopServer()
return
}
}
}

0 comments on commit 6d87af2

Please sign in to comment.