This program explores the question whether network i/o (e.g. waiting on socket read/write operations) will show up in the block profiler or not.
The program does the following:
- Start a TCP server via
net.Listen()
and wait for a client usingl.Accept()
. - Sleep for 1s
- Connect to the TCP server with a client using
net.Dial()
. - Let the server wait for a message from the client using
conn.Read()
- Sleep for 1s
- Send a
"hello world"
message from the client to the server usingconn.Write()
- Server prints the message it received
- Program exits
Given this program and assuming the block profiler captures network i/o, we'd expect to capture two major blocking events:
l.Accept()
waiting for 1s before a client connects.conn.Read()
waiting for 1s before receiving a message from the client
However, as you can see below, the block profiler captures only ~12ms
of activity related to channel operations involved in the listen/dial process. The accept/read activity however remains completely invisible.
This means that block profiler is generally not able to give a good idea about goroutines that are waiting on network i/o.