NetTalk Central

Author Topic: Bandwidth Throttling  (Read 5931 times)

useless

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
    • Email
Bandwidth Throttling
« on: October 12, 2012, 04:00:13 AM »
Is there anything in NT where I can bandwidth throttle ie restrict the bandwidth used to serve files as some are quite large and I dont want all the bandwidth to be used up when someone downloads a large file from a website? I can bandwidth throttle ports using the firewall/proxy server but this doesnt give me the control over the individual files downloaded from a website.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Bandwidth Throttling
« Reply #1 on: October 12, 2012, 04:37:14 AM »
you could have _some_ control by adding code to the .SendString method in the WebHandler.
However this would only throttle the Send between the application layer and the NetTalk layer. That would have an effect on the traffic flowing out, but it won't be an exact match.

Cheers
Bruce

useless

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
    • Email
Re: Bandwidth Throttling
« Reply #2 on: October 12, 2012, 08:54:41 AM »
Earlier on I was getting a server is busy message on your other site http://clarion.capesoft.com/, is this something I can throw up in some circumstances from within NT, like if I wanted to block an IP address or bandwidth throttle for example?

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Bandwidth Throttling
« Reply #3 on: October 12, 2012, 02:38:26 PM »
Hi,

Bandwidth throttling is going to be pretty tricky.

If you are trying to protect a slow contection probably cheaper to buy a faster connection than waste programmer hours trying to solve a problem that shouldnt exist.

If you want to protect yourself from abuse, you could restrict the number of concurrent download from a session ir IP to 1 or 2. That should be much easier.

Regards
Bill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Bandwidth Throttling
« Reply #4 on: October 12, 2012, 11:06:41 PM »
Hi Richard,

>> Earlier on I was getting a server is busy message on your other site http://clarion.capesoft.com/, is this something I can throw up in some circumstances from within NT, like if I wanted to block an IP address or bandwidth throttle for example?

yes absolutely. There is code in the WebServer procedure, in the StartThread method, that looks like this;

    If self.performance.NumberOfThreads >= self.MaxThreads and self.MaxThreads > 0
      self.SendError(500,'Server Busy','Server Busy, try again shortly')

This allows the server to limit the number of threads that are running at one time.

We're getting the error on the server at the moment because we've put in a DLL which is not ending the threads correctly - which means the system ultimately starves for threads. But that's an internal issue we're addressing.

Cheers
Bruce


Mike Grigsby

  • Sr. Member
  • ****
  • Posts: 380
    • Yahoo Instant Messenger - onthedotsoftware
    • View Profile
    • MyHomeAssets! Software (among others)
Re: Bandwidth Throttling
« Reply #5 on: October 13, 2012, 12:21:15 PM »
Adding to this snippet of code, Bruce, what would be a good way of sending users to another server if the first is busy? In other words, how could you add a URL that sends additional traffic to something like server2.mydomain.com?
Mike Grigsby
Credify Systems
Central Oregon, USA

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Bandwidth Throttling
« Reply #6 on: October 13, 2012, 10:44:40 PM »
Instead of the SendError you could do;

self._Redirect(RequestData,'url',Net:Web:Simple,Net:Web:CleanPost,Net:Web:TempRedirect)

( I haven't tried this myself.)

It's worth pointing out that the overload is not a normal condition - I've added a bug to the web server somewhere so it is behaving badly, and I have to figure out what's going on.

cheers
Bruce

useless

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
    • Email
Re: Bandwidth Throttling
« Reply #7 on: October 14, 2012, 11:53:59 PM »
> you could have _some_ control by adding code to the .SendString method in the WebHandler.

What I'm thinking here (havent investigated or looked at any NT code in any more detail yet) is I know the packets can be no more than 16kb, so if I can identify packets destined to an IP address (and or sessionID) to cater for multiple users at an IP address and restrict those packets in some way that would be best but how should the restriction be applied?

If one or more threads are created to serve one IP address (likely) I could put the thread(s) to sleep after X number of packets/bytes have been transmitted possibly giving me bandwith control but is more complex to add up the total packets sent across multiple threads.

Or if the packets to be transmitted are queued up somewhere like a global handler and the packets can sorted/identified by IP address then restricting the packets before they get sent would enable me to do this as well.

For example lets say I want a 16kb/sec performance, I could add up the packet size of each packet sent and at the 16kb threshold put the thread to sleep for 1 sec - (time to transmit the said packets). That would be good enough for me. In mail server terms this is no different to creating a Tarpit for spammers. http://en.wikipedia.org/wiki/Tarpit_%28networking%29

Would this be possible in NT?


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Bandwidth Throttling
« Reply #8 on: October 15, 2012, 05:21:36 AM »
sorry Richard, I'm not really understanding your approach here.

I guess your starting point would be to look at the code in the .SendString method, and then think about what you want to do from there.

cheers
Bruce

useless

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
    • Email
Re: Bandwidth Throttling
« Reply #9 on: October 15, 2012, 07:49:14 AM »
Is every packet sent out by NT passing through this procedure assuming this is the parent.send method?
NetClient.Send       PROCEDURE                             ! Declare Procedure 4

I can see in the Sendstring method

self.RequestData.WebServer.Packet.ToIP = self.RequestData.FromIP

so I have my IP addresses, but looking through the classes it looks like Send() is called from various places not just from inside SendString, so I'm thinking the .Send method might be a better place to add a flow control and possible meter to log how much data each IP address gets.

Is there anything else added to the packet to increase its size after the .send method?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Bandwidth Throttling
« Reply #10 on: October 15, 2012, 08:02:55 AM »
>> NetClient.Send

no, we're not using the NetClient class here (not even the NetWebClient class) so that's not the right name.

In the case of the WebHandler the place "everything goes through" is the .Send method of the _WebServer_ procedure.

self.RequestData.WebServer.Send()

That is certainly one place where you can do stats (albeit based on IP address, and not session ID).
You'd want to keep that code as simple as possible though to prevent any performance lag.

As far as the WebHandler goes, as far as I'm aware, everything goes through .SendString though.

>> Is there anything else added to the packet to increase its size after the .send method?
no.

Cheers
Bruce