I've rewritten several services in use by my employer in Go as HTTP servers. A common theme with these services are errors of the forms "too many open files", "no such host" and the like. I'm not entirely sure what could cause the DNS errors, but it's my belief the root cause is accepting too many connections, and then not having any available file descriptors remaining to service those requests, as my handlers open file descriptors as part of the handling logic.Many of the services have grown ad-hoc limiting and pools to manage various resources but these are clunky and there's a lot of guess work. In addition, net/http.Server doesn't provide any built in mechanism to limit active connections, and the logic that wraps of the handling of each client is not exposed (net/http.Server.newConn), making it difficult to manage calling Accept() myself and invoking the usual net/http handling routines for each connection.What's the best approach here?
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
There is no guarantee that x will be 2. I believe it will always be with GOMAXPROCS=1, since the sole thread dedicated to running goroutines in user code hasn't handed over to the scheduler yet. Even if the thread is preempted, another goroutine won't run until the next blocking call (the channel receive following). However with GOMAXPROCS>1, it's definitely possible due to kernel preemptive scheduling, and thus is a race. That said, you shouldn't rely on GOMAXPROCS=1 to enforce expected behaviour.
I don't believe he's arguing that. What he's saying is that is doesn't matter here, since we only care about the limit, not the order.
On Fri, May 24, 2013 at 2:57 AM, James Bardin <j.ba...@gmail.com> wrote:I don't believe he's arguing that. What he's saying is that is doesn't matter here, since we only care about the limit, not the order.
it is.
the following message is a verbatim quote from https://groups.google.com/d/msg/golang-dev/ShqsqvCzkWg/9WGj2yPK9xYJ,please do read the whole thread, and esp. consider the fact that the semaphore example in Effective Gois changed to use the receiving-as-Lock implementation (and Gustavo's program is using precisely the oldimplementation of the semaphore [sending-as-Lock]).
On Thu, May 23, 2013 at 4:54 PM, minux <minu...@gmail.com> wrote:I'm not using it as a lock, as a lock has well defined memory barrier
> is changed to use the receiving-as-Lock implementation (and Gustavo's
> program is using precisely the old implementation of the
> semaphore [sending-as-Lock]).
semantics that a channel does not, and I'm not suggesting that. I'm
actually trusting on its blocking properties, as stated in the
specification:
"""
The capacity, in number of elements, sets the size of the buffer in
the channel. If the capacity is greater than zero, the channel is
asynchronous: communication operations succeed without blocking if the
buffer is not full (sends) or not empty (receives), and elements are
received in the order they are sent.
"""
This implies it blocks if the channel is full. This is also confirmed
in Effective Go:
"""
If the channel has a buffer, the sender blocks only until the value
has been copied to the buffer; if the buffer is full, this means
waiting until some receiver has retrieved a value.
"""
That's what the spec says, but even besides it, it would be extremely
ironic to have all the care the Go designers take to have things being
understandable, and then create such subtle behavior in the core
communication primitive of the language.
On Fri, May 24, 2013 at 10:29 AM, minux <minu...@gmail.com> wrote:I'm not implementing a semaphore. A semaphore implies memory barrier
> how is your use of buffered channel different from the example in my last
> reply and the semaphore example in Effective Go?
semantics that I'm not using.
I agree with the points made in that thread, but it's addressing something else.
> the quoted thread happens almost one year ago, and the MM docs remains
On Fri, May 24, 2013 at 11:48 AM, minux <minu...@gmail.com> wrote:(...)
>> I'm not implementing a semaphore. A semaphore implies memory barrier
>> semantics that I'm not using.
> How is that different from your program?You already said that, and I already explained. What I implemented
requires only what the specification and memory model define as valid
and correct.
This is correct, unrelated, and irrelevant. I did not implement a
semaphore. It's not a memory barrier.
On Fri, May 24, 2013 at 1:43 PM, roger peppe <rogp...@gmail.com> wrote:A semaphore implies memory barrier semantics. It's not a semaphore.
> There is no memory barrier required in this program, but
> it nonetheless uses a channel as a semaphore.
Happens-before requires memory barrier semantics. If there was such a
> If we do have that guarantee, that's surely a
> "happens before" relationship as defined by the
> memory model.
guarantee, the implementation I pasted would be an actual semaphore,
but it's not. It relies solely on the fact the channel blocks as per
the spec, and on the fact the compiler cannot reorder statements in a
way that would change the meaning of the program, per the memory
model.
"""
That is, compilers and processors may reorder the reads and writes
executed within a single goroutine only when the reordering does not
change the behavior within that goroutine as defined by the language
specification.
"""
On Fri, May 24, 2013 at 2:20 PM, minux <minu...@gmail.com> wrote:Have a look at the actual document from Dijkstra from 1965 and try to
>> A semaphore implies memory barrier semantics. It's not a semaphore.
> Why semaphore implies memory barrier semantics?
> From http://en.wikipedia.org/wiki/Semaphore_(programming):
convince yourself that a memory barrier is not required:
http://www.cs.utexas.edu/users/EWD/ewd01xx/EWD123.PDF
> is that the process() call is done after sem <- 1. but why that's true?We've already covered this.
On Fri, May 24, 2013 at 3:34 PM, minux <minu...@gmail.com> wrote:We've already covered all of that. I'm done with this thread as it
> these two statement contradict with each other.
stopped being useful for anyone, including ourselves.