Creating a Proxy Server with Go
codingcookies.com
Creating a Proxy Server with Go
1–10 of 20 posts
Re: Creating a Proxy Server with Go
#2 // The booleans representing the free active connection spaces.
spaces := make(chan bool, *maxConnections)
// Initialize the spaces
for i := 0; i
}Is this really how people use go???
Re: Creating a Proxy Server with Go
#3I'm not sure I agree with how channels are used here. What's the point of this spaces chan? Why couldn't a simple atomic counter solve this (see sync/atomic)? Why allocate a thousand bools? // The booleans representing the free active connection spaces. spaces := make(chan bool, *maxConnections) // Initialize the spaces for i := 0; i } Is this really how people use go???
Re: Creating a Proxy Server with Go
#4I'm not sure I agree with how channels are used here. What's the point of this spaces chan? Why couldn't a simple atomic counter solve this (see sync/atomic)? Why allocate a thousand bools? // The booleans representing the free active connection spaces. spaces := make(chan bool, *maxConnections) // Initialize the spaces for i := 0; i } Is this really how people use go???
Looking at this some more... Why wouldn't you just make the waiting chan buffered and eliminate any tracking of connections.
You're right that sync/atomic could've taken care of this, I wasn't aware of that package and figured channels were the way to go in Go.
As for making the waiting chan buffered, the reason I wanted to keep track of pending connections and active connections is because I'd like to proxy from a high-power server to a low-power server such as a Raspberry Pi. I agree with you that it could have done without though.
Thanks for the tips! :-)
Re: Creating a Proxy Server with Go
#5Earlier quoted context omitted.
Looking at this some more... Why wouldn't you just make the waiting chan buffered and eliminate any tracking of connections.
Hey, poster here. You're right that sync/atomic could've taken care of this, I wasn't aware of that package and figured channels were the way to go in Go. As for making the waiting chan buffered, the reason I wanted to keep track of pending connections and active connections is because I'd like to proxy from a high-power server to a low-power server such as a Raspberry Pi. I agree with you that it could have done wit…
One of the last slides: http://talks.golang.org/2012/concurrency.slide#54
Re: Creating a Proxy Server with Go
#6Earlier quoted context omitted.
Hey, poster here. You're right that sync/atomic could've taken care of this, I wasn't aware of that package and figured channels were the way to go in Go. As for making the waiting chan buffered, the reason I wanted to keep track of pending connections and active connections is because I'd like to proxy from a high-power server to a low-power server such as a Raspberry Pi. I agree with you that it could have done wit…
So perhaps I was a bit harsh. Do check out this set of slides though: http://talks.golang.org/2012/concurrency.slide One of the last slides: http://talks.golang.org/2012/concurrency.slide#54
Re: Creating a Proxy Server with Go
#7I'm not sure I agree with how channels are used here. What's the point of this spaces chan? Why couldn't a simple atomic counter solve this (see sync/atomic)? Why allocate a thousand bools? // The booleans representing the free active connection spaces. spaces := make(chan bool, *maxConnections) // Initialize the spaces for i := 0; i } Is this really how people use go???
Re: Creating a Proxy Server with Go
#8I'm not sure I agree with how channels are used here. What's the point of this spaces chan? Why couldn't a simple atomic counter solve this (see sync/atomic)? Why allocate a thousand bools? // The booleans representing the free active connection spaces. spaces := make(chan bool, *maxConnections) // Initialize the spaces for i := 0; i } Is this really how people use go???
Re: Creating a Proxy Server with Go
#9I know it's possible to pull select() into Golang programs (I ended up having to, to write a fast port scanner), but Golang people look at you weirdly when you tell them you did that.
Re: Creating a Proxy Server with Go
#10I know it's irrational, but it drives me a little nuts how the proxy idiom in go is "two goroutines implementing socket-to-socket copy". The inner handler loop of a proxy is a place where, to me, select/poll might actually make the code easier to follow; also, the idiom doubles the number of goroutines required to handle a given connection load, and while goroutines are cheap, they aren't free. I know it's possible t…