golang/go

net: add tryRead() method to Conn

tema3210 opened this issue · 6 comments

On my last project i were very discouraged by the feature of test connection for the data is present is absent from language. We needed high perfomance, around 1-2 millions of connections, but we have to look for the third party libraries for epoll/kqueue integration in order to get the way to read and do something with data only when it's arrived, not waiting, such decision was made because even waiting goroutines in this case take around 4-8 GB of wasted memory.

P.S add such thing for tls.conn to.

Or perhaps a special case of make(chan) which takes io.Reader objects and provides the next readable member via <-c

func f(list ...net.Conn) error {
   c := make(chan, list...)
   buf := make([]byte, kSize)

   for r := range c {
      len, err := r.Read(buf)
      if err != nil { return err }
      something(buf[:len])
   }
}

@networkimprov thanks, it's helpful

@networkimprov and where i can read about special cases?

What I suggested would require a change to the language, so doesn't help right now.

This is also raised in #15735 by @bradfitz

Or perhaps a special case of make(chan) which takes io.Reader objects and provides the next readable member via <-c

func f(list ...net.Conn) error {
   c := make(chan, list...)
   buf := make([]byte, kSize)

   for r := range c {
      len, err := r.Read(buf)
      if err != nil { return err }
      something(buf[:len])
   }
}

And how do i add net.Conn's to such channel?

Let's take this discussion to golang-nuts. We already have #15735 and I don't see anything new here.