fix #80

Signed-off-by: arraykeys@gmail.com <arraykeys@gmail.com>
This commit is contained in:
arraykeys@gmail.com
2018-05-22 11:21:58 +08:00
parent 8649bbc191
commit f559fb1cae
5 changed files with 19 additions and 7 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ goproxy
*.exe *.exe
*.exe~ *.exe~
.* .*
*.prof
!.gitignore !.gitignore
release-* release-*
proxy.crt proxy.crt

View File

@ -10,6 +10,9 @@ v4.8
5.优化了sps日志输出. 5.优化了sps日志输出.
6.--debug参数增加了Profiling功能,可以保存cpu,内存等多种调试数据到文件. 6.--debug参数增加了Profiling功能,可以保存cpu,内存等多种调试数据到文件.
7.优化了服务注册,避免了不必要的内存开销. 7.优化了服务注册,避免了不必要的内存开销.
8.增加了Dockerfile和docker安装手册.
9.优化了ioCopy避免了内存泄漏,大大提升了内存占用的稳定性.
v4.7 v4.7

View File

@ -76,7 +76,8 @@ func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interfac
}() }()
} }
func ioCopy(dst io.ReadWriter, src io.ReadWriter) (err error) { func ioCopy(dst io.ReadWriter, src io.ReadWriter) (err error) {
buf := make([]byte, 32*1024) buf := LeakyBuffer.Get()
defer LeakyBuffer.Put(buf)
n := 0 n := 0
for { for {
n, err = src.Read(buf) n, err = src.Read(buf)

View File

@ -1,15 +1,15 @@
// Provides leaky buffer, based on the example in Effective Go. // Provides leaky buffer, based on the example in Effective Go.
package ss package utils
type LeakyBuf struct { type LeakyBuf struct {
bufSize int // size of each buffer bufSize int // size of each buffer
freeList chan []byte freeList chan []byte
} }
const leakyBufSize = 4108 // data.len(2) + hmacsha1(10) + data(4096) const LeakyBufSize = 2048 // data.len(2) + hmacsha1(10) + data(4096)
const maxNBuf = 2048 const maxNBuf = 2048
var leakyBuf = NewLeakyBuf(maxNBuf, leakyBufSize) var LeakyBuffer = NewLeakyBuf(maxNBuf, LeakyBufSize)
// NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each // NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each
// with bufSize bytes. // with bufSize bytes.

View File

@ -10,8 +10,15 @@ import (
"net" "net"
"os" "os"
"strconv" "strconv"
"github.com/snail007/goproxy/utils"
) )
const leakyBufSize = 4108 // data.len(2) + hmacsha1(10) + data(4096)
const maxNBuf = 2048
var leakyBuf = utils.NewLeakyBuf(maxNBuf, leakyBufSize)
func IsFileExists(path string) (bool, error) { func IsFileExists(path string) (bool, error) {
stat, err := os.Stat(path) stat, err := os.Stat(path)
if err == nil { if err == nil {