The important factors: 1) the larger the buffer the fewer system calls that need to be made 2) the larger the buffer the more memory use which can be significant with many simultaneous connections
You need to remember that with correct socket options the kernel is already buffering, and adding your own buffering on top may not be needed 3) really large user space (Go) buffers may be needed if processing a really fast fat pipe > On Dec 31, 2019, at 9:23 AM, Ron Wahler <ron.wah...@gmail.com> wrote: > > > Thanks for all the great responses. > > How much of the read behavior is in the golang underlying code on the read > and how much is > on the underlying OS driver that implements the behavior of the read. I > understand the stream nature of the TCP connection and I handle that in my > code, I was just looking to optimize the buffer allocation for the read on > each packet of the stream so I don't have to over allocate the buf if I > scaled out my function to be concurrent. From the responses so far I think I > just have to pick a buffer size for the Read() or the ReadAtLeast() and just > process multiple buffers with my pre-allocated guess on the buffer size as I > am already doing. > > I was also looking to understand the read implementation of GoLand and how it > utilizes the underlying drivers, so any info on that or where to read the > code for golang integration with the drivers would be great. > > cheers, > Ron > >> On Friday, December 27, 2019 at 5:11:42 PM UTC-7, Ron Wahler wrote: >> I am looking for a net.conn standard read that would return a data buffer >> the exact size of the read. I am trying to read an unknown amount of byte >> data from the connection. With the read i am using I am required to >> pre-allocate a buffer and pass that buffer to the read. I am looking for a >> read that works more like the ReadString , but is for a byte slice. >> >> // I want something similar to this read that returns the read string into >> the message string. >> message, err := bufio.NewReader(ServerConn).ReadString('\n') >> >> if ( err != nil ){ >> >> fmt.Println("RELAY: ERROR: Reg Message read err:", >> err) >> >> return >> >> } >> >> >> >> >> >> // had to preallocate a buffer, but I want a read to return me a buffer so I >> don't have to guess how big to make it. >> >> buf := make([]byte, 1024*32) >> >> // READ FROM CLIENT >> >> nBytes, err := Csrc.Read(buf) >> >> >> >> >> >> Is this not possible, I have not seen any examples that would indicate that >> there is a standard library that would do something like what I am looking >> for. >> >> >> >> thanks, >> >> Ron >> > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/0e735f0e-dfb1-4e1f-9a2c-1b153be20514%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/060D2B13-71A9-42AA-9002-0924E1A051CB%40ix.netcom.com.