Coder Social home page Coder Social logo

关于PutBufPoolCopy about nps HOT 4 CLOSED

ehang-io avatar ehang-io commented on July 17, 2024
关于PutBufPoolCopy

from nps.

Comments (4)

traffic-go avatar traffic-go commented on July 17, 2024

go version go1.11.4 windows/amd64

from nps.

cnlh avatar cnlh commented on July 17, 2024

io.Copy,每次都需要make一个特定长度的[]byte,会增大gc负担 应该使用sync.Pool,你可以测试下多条连接高并发的情况,不过最新版已经不再使用io.copy的方式

from nps.

traffic-go avatar traffic-go commented on July 17, 2024

如果关于gc的原因而使用sync.Pool,我感觉linkProcess函数应该这样写更合理一些。因为每次Read最大也就是poolSizeCopy的大小,而Read函数读取出了覆盖到buf内存空间的大小,发送也指定了到覆盖的位置,没有必要每次有数据重新从池获取然后在put进去。golang初学选手,强项是c。如有不对的地方请谅解。

link.Conn = lib.NewConn(server)

buf := lib.BufPoolCopy.Get().([]byte)						//[+]
for {
	//buf := lib.BufPoolCopy.Get().([]byte)					//[-]
	if n, err := server.Read(buf); err != nil {
		//lib.PutBufPoolCopy(buf)					//[-]
		s.tunnel.SendMsg([]byte(lib.IO_EOF), link)
		break
	} else {
		if _, err := s.tunnel.SendMsg(buf[:n], link); err != nil {
			//lib.PutBufPoolCopy(buf)				//[-]
			c.Close()
			break
		}
		//lib.PutBufPoolCopy(buf)					//[-]
		//if link.ConnType == utils.CONN_UDP {
		//	c.Close()
		//	break
		//}
	}
}
lib.PutBufPoolCopy(buf)							        //[+]
s.Lock()

from nps.

cnlh avatar cnlh commented on July 17, 2024

这个地方和服务端同类问题是我的错误 上次重构遗落了 感谢反馈!
我水平有限,欢迎pr或指教

from nps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.