In this case it looks like to be correct you must set the deadline before reading from the network, and given reading from the network can block, the cost of setting the deadline is small.
On Sat, 6 Apr 2019 at 21:47, Santhosh T <santhosh.tek...@gmail.com> wrote: > > Hi Dave, > > my mistake, bufr is backed by net.Conn > > bufr := bufio.newReader(netConn) > for numEntries >0 { > numEntries-- > netConn.setReadDeadline(timeNow().add(heartbeatTimeout) > entry.decode(bufr) > process(entry) > } > > thanks > Santhosh > > On Sat, Apr 6, 2019 at 4:09 PM Dave Cheney <d...@cheney.net> wrote: >> >> Thanks for the explanation. Two things >> >> 1. As this is a question about how to write a Go program, you should >> move this thread to golang-nuts, golang-dev is only for the >> development of Go. >> 2. From the sample code you provided, there is no call to >> netConn.Read, so setting the deadline is unnecessary. Please move the >> discussion to golang-nuts and consider posting a larger piece of >> sample code that shows the interaction with the network. >> >> On Sat, 6 Apr 2019 at 21:27, Santhosh T <santhosh.tek...@gmail.com> wrote: >> > >> > Hi Dave, >> > >> > I am implementing raft protocol, where leader sends bunch of entries over >> > net.Conn to follower. >> > >> > leader can send large number of entries in single net.Conn.write. >> > if follower does not hear from leader within configured heartbeatTimeout, >> > it has to start election. >> > >> > currently follower implementation is something like this: >> > >> > for numEntries >0 { >> > numEntries-- >> > netConn.setReadDeadline(timeNow().add(heartbeatTimeout) >> > entry.decode(bufr) >> > process(entry) >> > } >> > >> > if numEntries is say 10000, i would be spending significant time in >> > makeing syscalls for setReaddeadline >> > btw, i have not done any benchmark yet. I asked the question our of >> > curiosity. >> > >> > What i was planning to do to optimize it is: >> > as i am reading entry from bufr, in most cases the entry might be >> > already in the buffer. in such case >> > i can avoid setting readDeadline. so set deadline, only when bufr calls >> > read on underlaying reader. >> > >> > hope i am clear... >> > >> > thanks >> > Santhosh >> > >> > On Sat, Apr 6, 2019 at 2:53 PM Dave Cheney <d...@cheney.net> wrote: >> >> >> >> Hi Santhosh, >> >> >> >> Calling SetDeadline does not _directly_ trigger a syscall, but it does >> >> have several other observable side effects. What is the problem you >> >> are facing that lead you to ask this question? >> >> >> >> Thanks >> >> >> >> Dave >> >> >> >> On Sat, 6 Apr 2019 at 20:20, Santhosh Kumar T <santhosh.tek...@gmail.com> >> >> wrote: >> >> > >> >> > does net.Conn.SetDeadLine makes syscall ? >> >> > >> >> > thanks >> >> > santhosh >> >> > >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups "golang-dev" group. >> >> > To unsubscribe from this group and stop receiving emails from it, send >> >> > an email to golang-dev+unsubscr...@googlegroups.com. >> >> > For more options, visit https://groups.google.com/d/optout. -- 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. For more options, visit https://groups.google.com/d/optout.