内存优化

pull/1219/head
刘河 2019-01-13 22:02:58 +08:00
parent 72290275cc
commit 53e57ea70d
3 changed files with 10 additions and 18 deletions

View File

@ -6,7 +6,7 @@ easyProxy是一款轻量级、高性能、功能最为强大的**内网穿透**
目前市面上提供类似服务的有花生壳、TeamView、GoToMyCloud等等但要使用第三方的公网服务器就必须为第三方付费并且这些服务都有各种各样的限制此外由于数据包会流经第三方因此对数据安全也是一大隐患。 目前市面上提供类似服务的有花生壳、TeamView、GoToMyCloud等等但要使用第三方的公网服务器就必须为第三方付费并且这些服务都有各种各样的限制此外由于数据包会流经第三方因此对数据安全也是一大隐患。
支持客户端与服务端连接中断自动重连多路传输大大的提高请求处理速度go语言编写无第三方依赖。 支持客户端与服务端连接中断自动重连多路传输大大的提高请求处理速度go语言编写无第三方依赖各个平台都已经编译在release中普通个人场景下内存使用量在10M以下
## 背景 ## 背景
![image](https://github.com/cnlh/easyProxy/blob/master/image/web.png?raw=true) ![image](https://github.com/cnlh/easyProxy/blob/master/image/web.png?raw=true)
@ -185,11 +185,7 @@ server {
listen 80; listen 80;
server_name a.ourcauc.com; server_name a.ourcauc.com;
location / { location / {
proxy_set_header X-Real-IP $remote_addr; #其他配置例如ssl
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:8024; proxy_pass http://127.0.0.1:8024;
} }
} }

View File

@ -147,15 +147,14 @@ func GetIntNoerrByStr(str string) int {
// io.copy的优化版读取buffer长度原为32*1024与snappy不同导致读取出的内容存在差异不利于解密特此修改 // io.copy的优化版读取buffer长度原为32*1024与snappy不同导致读取出的内容存在差异不利于解密特此修改
//废除 //内存优化 用到pool快速回收
func copyBuffer(dst io.Writer, src io.Reader) (written int64, err error) { func copyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
//TODO 回收问题
buf := bufPoolCopy.Get().([]byte)
defer bufPoolCopy.Put(buf)
for { for {
buf := bufPoolCopy.Get().([]byte)
nr, er := src.Read(buf) nr, er := src.Read(buf)
if nr > 0 { if nr > 0 {
nw, ew := dst.Write(buf[0:nr]) nw, ew := dst.Write(buf[0:nr])
bufPoolCopy.Put(buf)
if nw > 0 { if nw > 0 {
written += int64(nw) written += int64(nw)
} }
@ -167,6 +166,8 @@ func copyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
err = io.ErrShortWrite err = io.ErrShortWrite
break break
} }
}else {
bufPoolCopy.Put(buf)
} }
if er != nil { if er != nil {
if er != io.EOF { if er != io.EOF {

View File

@ -36,11 +36,6 @@
server_name a.proxy.com b.proxy.com;#*.proxy.com server_name a.proxy.com b.proxy.com;#*.proxy.com
#ssl #ssl
<b>location / { <b>location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:{{.proxyPort}}; proxy_pass http://127.0.0.1:{{.proxyPort}};
}</b> }</b>
} }
@ -140,10 +135,10 @@
<div class="tile"> <div class="tile">
<p> <p>
<b></b> <b></b>
<li>./easyProxy -mode=webServer -tcpport=8284</li> <li>./proxy_server</li>
<li>./easyProxy -server={{.ip}}:{{.p}} -vkey=xxx</li> <li>./proxy_client -server={{.ip}}:{{.p}} -vkey=xxx</li>
</p> </p>
<p><b>./easyProxy -server={{.ip}}:{{.p}} -vkey=ccc./easyProxy <p><b>./proxy_client -server={{.ip}}:{{.p}} -vkey=ccc./proxy_client
-server={{.ip}}:{{.p}} -vkey=ccc,dddvkey</b></p> -server={{.ip}}:{{.p}} -vkey=ccc,dddvkey</b></p>
</div> </div>
</div> </div>