Awful Programming Advice

Sep 14, 2009 16:21

I just came across a blog post going over that old saw of Object Oriented Design, a square being a subclass of a rectangle ( Read more... )

Leave a comment

allter September 15 2009, 06:35:44 UTC
The reason why such API doesn't exist is that it's not flexible enough while adding conciderable overhead to the raw syscall-based API. For example, this API states that any 'can read' condition will lead to unconditional method call ( ... )

Reply

(The comment has been removed)

bramcohen September 15 2009, 14:53:56 UTC
If you're trying to rate limit a download connection you can do it (awkwardly) by only reading from the socket at the rate you want. This will cause the sending side to slow down, although it's kind of clumsy under the hood due to technical issues with how TCP works. There unfortunately isn't a better way to rate limit TCP on the receiving end.

Reply

(The comment has been removed)

jered September 15 2009, 19:12:01 UTC
If it's a protocol I'm designing myself, I'd explicitly incorporate the rate limiting into the protocol.

You're awfully trusting of unknown clients....

Reply

(The comment has been removed)

bramcohen September 15 2009, 22:39:23 UTC
Requesting smaller chunks doesn't really do what you want - it tends to make packets come in spurts rather than steadily, and if you make the chunks small enough it tends to limit the thoughput to less than what you intended. Congestion control is hard.

Reply

bramcohen September 15 2009, 22:38:18 UTC
Trusting people not to flood you is something you have to accept if you want to be on the internet.

Reply

bramcohen September 15 2009, 22:33:29 UTC
Rate limiting is a difficult problem. TCP is window-based rather than rate-based, for fairly good reasons, and controlling a rate by adjusting the receive window is clumsy at best. When using a new protocol you can simply give the sending side a max rate and the other side can implement it straightforwardly with token buckets or something like that, but in a legacy system that isn't an option.

In any case, yes, 99% of the time simply having the callback hand over the new data rather than reporting that a read is possible and requiring another call to get it is simpler and higher performing behavior. I did say there's a lot of subtlety even to that fairly simple API.

Reply

bramcohen September 15 2009, 22:37:42 UTC
TCP is window-based rather than rate-based, for good reasons, and controlling rate by limiting the receive window is clumsy at best. For a new protocol one can simply rate limit on the sending side, which works far better, but that isn't always an option in legacy systems.

In any case, yeah, most of the time having a callback simply hand over the data which was received is more straightforward and higher performing. I did say there's a lot of subtlety to this API.

Reply

allter September 15 2009, 21:22:34 UTC
> I've written code substantially similar to what Bram describes in C, Python, and C ( ... )

Reply


Leave a comment

Up