multithreading - Goroutine I/O scheduling -
golangs goroutines present interface of blocking i/o goroutine (-programmer). behind scenes runtime naturally uses kind of non-blocking i/o prevent os suspending os-thread, runtime can run goroutine on top of os thread while i/o performed.
when runtime consider i/o performed can reschedule goroutine?
to make clear, assuming have net.tcpconn
call write
on, when can expect goroutine rescheduled?
conn, err := net.dial("tcp", serveraddr) conn.write(buffer) timestamp = time.now()
that when can expect timestamp taken?
- when buffer has been copied golang runtime?
- when buffer has been copied runtime , os's kernel space?
- when buffer has been copied runtime, kernel space , additionally nic's send buffer?
- when buffer has been sent on network/from nic?
- when buffer has been acknowledged recieve ends tcp stack?
you can have in file https://github.com/golang/go/blob/master/src/net/fd_unix.go (write function).
basically, depends whether socket buffer has enough space or not.
if there enough space in socket buffer accommodate size of write operation, data written socket buffer. guess corresponds second answer. additionally, kernel may send packet (or add nic queues), independent go runtime.
if there not enough space in socket buffer accommodate whole write operation, part of data written socket buffer. then, call block (via runtime polling engine) until kernel has made space in socket buffer (by sending packets). space available, , data have been copied, call unblock.
you should consider timestamp taken when net package has written whole buffer in socket buffer via system call.
Comments
Post a Comment