From f559fb1cae2baced744db3abb35487b2f0ad8c84 Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Tue, 22 May 2018 11:21:58 +0800 Subject: [PATCH] fix #58 fix #80 Signed-off-by: arraykeys@gmail.com --- .gitignore | 1 + CHANGELOG | 9 ++++++--- utils/functions.go | 3 ++- utils/{ss => }/leakybuf.go | 6 +++--- utils/ss/util.go | 7 +++++++ 5 files changed, 19 insertions(+), 7 deletions(-) rename utils/{ss => }/leakybuf.go (88%) diff --git a/.gitignore b/.gitignore index 56cad34..c64fc58 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ goproxy *.exe *.exe~ .* +*.prof !.gitignore release-* proxy.crt diff --git a/CHANGELOG b/CHANGELOG index 2f7edd2..5392e7f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,14 +2,17 @@ proxy更新日志 v4.8 1.优化了SPS连接HTTP上级的指令,避免了某些代理不响应的问题. 2.SPS功能增加了参数: ---disable-http:禁用http(s)代理 ---disable-socks:禁用socks代理 -默认都是false(开启). + --disable-http:禁用http(s)代理 + --disable-socks:禁用socks代理 + 默认都是false(开启). 3.重构了部分代码的日志部分,保证了日志按着预期输出. 4.修复了sps\http代理初始化服务的时机不正确,导致nil异常的bug. 5.优化了sps日志输出. 6.--debug参数增加了Profiling功能,可以保存cpu,内存等多种调试数据到文件. 7.优化了服务注册,避免了不必要的内存开销. +8.增加了Dockerfile和docker安装手册. +9.优化了ioCopy避免了内存泄漏,大大提升了内存占用的稳定性. + v4.7 diff --git a/utils/functions.go b/utils/functions.go index ddb588f..ea4f167 100755 --- a/utils/functions.go +++ b/utils/functions.go @@ -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) { - buf := make([]byte, 32*1024) + buf := LeakyBuffer.Get() + defer LeakyBuffer.Put(buf) n := 0 for { n, err = src.Read(buf) diff --git a/utils/ss/leakybuf.go b/utils/leakybuf.go similarity index 88% rename from utils/ss/leakybuf.go rename to utils/leakybuf.go index 029d93f..513c90e 100644 --- a/utils/ss/leakybuf.go +++ b/utils/leakybuf.go @@ -1,15 +1,15 @@ // Provides leaky buffer, based on the example in Effective Go. -package ss +package utils type LeakyBuf struct { bufSize int // size of each buffer 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 -var leakyBuf = NewLeakyBuf(maxNBuf, leakyBufSize) +var LeakyBuffer = NewLeakyBuf(maxNBuf, LeakyBufSize) // NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each // with bufSize bytes. diff --git a/utils/ss/util.go b/utils/ss/util.go index 290c4a7..dcc56db 100644 --- a/utils/ss/util.go +++ b/utils/ss/util.go @@ -10,8 +10,15 @@ import ( "net" "os" "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) { stat, err := os.Stat(path) if err == nil {