• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Capping of sockets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Capping of sockets


  • Subject: Re: Capping of sockets
  • From: David Aames <email@hidden>
  • Date: Sat, 10 Jun 2006 20:04:30 +0100


On 9 Jun 2006, at 23:08, james woodyatt wrote:

On Jun 9, 2006, at 14:36, David Aames wrote:
On 9 Jun 2006, at 22:29, Scott Ribe wrote:

Any ideas on how to go about implement capping?

Sorry, you're not even close. Data is still being read into buffers
regardless of whether or not your app reads it, until the window fills up,
at which point... You have to do this at a lower level, mucking about with
TCP congestion control. I'd suggest Richard Stevens' books on TCP/ IP...

So is that the (only) way all desktop apps implement it? (eg. Azureus comes to mind which is written in Java)

It sounds like you want to implement rate limiting in the application layer. The "traditional family values" approach to this problem is not to limit the rate at which you *read* octets, but rather to limit the rate at which you *write* them.


The algorithm you want is called a "token bucket". Every N milliseconds or so, you put a constant quantity of tokens "into" the bucket. If the bucket "overflows" you dump the "extra" tokens on the floor. Whenever you have octets to write, you pull enough tokens out of the bucket to cover the cost of transmitting them. If there aren't enough tokens in the bucket, you queue whatever octets you can't afford to transmit. If the holding queue has octets in it when it's time to add tokens to the bucket, you spend the tokens immediately instead by transmitting from the queue. If the holding queue gets too long, then you either need to throttle back on the octet source or decide which octets to drop.

Hello all again,

After tinkering with sockets all day (instead of revising for my exams) I've finally managed to implement CPU efficient capping. I'm using a combinations of APIs (CFSocket + BSD sockets + CFRunLoop + NSTimer) to minimize the CPU usage. So the results I've achieved: 0% CPU on one socket (download capped with adjustable burst rate) which is pretty impressive having in mind that my previous solution was using ~80% of one the CPUs. Upload capping for one socket takes about 0.7% CPU _but_ this is the un-optimized version: I *think* I'm going to manage to put it at least to 0.1% and hopefully to 0%. After I finish my exams I'm going to write a howto/article on how I achieved all this + source code. Thanks for all your help.

Regards


HTH...


-- james woodyatt <email@hidden> member of technical staff apple computer, inc.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Capping of sockets (From: Scott Ribe <email@hidden>)
 >Re: Capping of sockets (From: David Aames <email@hidden>)
 >Re: Capping of sockets (From: james woodyatt <email@hidden>)

  • Prev by Date: Re: Capping of sockets
  • Next by Date: CFSocket callbacks and thread-safety
  • Previous by thread: Re: Capping of sockets
  • Next by thread: Re: Capping of sockets
  • Index(es):
    • Date
    • Thread