On Mon, Nov 18, 2013 at 3:32 AM, Mike Andrews <
m...@xoba.com> wrote:
>
> i'm also wondering about what guarantees or expectations i could have about
> latency; e.g., could i expect those 100k/s to each be served in 10ms or
> under (for small responses, maybe <100 bytes)? i mean, since go-lang is not
> just raw linux with user-code-and-o/s-calls (like in c-language), but a
> whole additional layer of go's synchronization and scheduling? so for
> instance, in the go-lang net/http server architecture, there are two points
> in the code i'm concerned or curious about ---
>
> 1.
http://golang.org/src/pkg/net/http/server.go?s=45668:45714#L1542 --- the
> "rw, e := l.Accept()" line where go-lang is waiting for a new tcp/ip socket
> connection.
>
> 2.
http://golang.org/src/pkg/net/http/server.go?s=45668:45714#L1564 --- the
> "go c.serve()" line where go-lang is being asked to schedule a go-routine to
> handle the i/o on that new tcp/ip connection.
>
> questions or concerns i have are:
>
> 1. in the midst of potentially thousands (or 10's of thousands) of other
> go-routines competing for cpu (in a 100k/s http server), might the "rw, e :=
> l.Accept()" line receiving new tcp/ip connections not get called for
> extended periods of time? i mean, linux might notify the process in a
> microsecond, but go-lang's runtime might decide to wait 100ms before calling
> "l.Accept()?"
First I'll say that obviously the only thing that counts is measurement.
That said, your question is not quite correctly stated. The Go code
will have already called l.Accept. The descriptor will have been
added to the runtime poller. The question is the length of time it
will take from when the OS notifies the poller that the descriptor is
ready (via returning from epoll_wait) to when the goroutine will be
scheduled to run. This is obviously a key element of the Go runtime,
and it has been heavily optimized. If the program is otherwise idle
letting the goroutine continue will be quite fast, comparable to a
similar C program. But it is certainly true that in a loaded system
for the Go code to continue running past the point of Accept will mean
waiting for the Go runtime to allocate a thread, and the length of
time that will take depends entirely on the load.
> 2. after accepting a new connection, might the "go c.serve()" line not cause
> a go-routine to start running immediately? again, i guess my question or
> concern is that the go-lang scheduler might be free to assign priorities in
> a way i'd disagree with.
Yes, again, in a loaded system, a new goroutine will start soon but it
will not start right away. It will wait until some thread is
available.
Ian