473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

transfer rate limiting in socket.py

Hi folks,

I have a need in a network data distribution application to send out
data to folks who want it using the protocol of their choice. I´d
like it to support a variety of protocols and I don´t want to
implement any of them :-)
http, ftp (via ftplib) , https (dunno how yet), ssl, ssh, sftp (via
paramiko)

The thing is... I want rate-limiting so that in the case of a failure
of a single client
I don´t penalize the other clients, or if my server (which is acting
as a client pushing to remote servers.) goes down, it doesn´t saturate
the link when it comes back.

So I want to have all the protocols limit the number of bytes they send
per second.
It looks like the easiest way to do this is to dive into socket.py...
and look! it says:

# Wrapper module for _socket, providing some additional facilities
# implemented in Python.

note the ´additional facilities implemented in python´ ...

so we just add logic to:
-- add a ´maxrate´ argument to the constructor and/or an attribute to
modify the setting...
-- tally bytes, and time, and know when we are going ´too fast´
-- when too fast.. in the ´flush´ routine, in the synchronous case,
sleep for the correct time to come back under budget. in the async,
return without writing.
-- do something similar for reading.

Anybody think this would be fun?

Jun 16 '06 #1
3 2503

I looked at twisted briefly. It looks like it is server oriented.
Does it work in for clients initiating connections?
Jean-Paul Calderone wrote:
On 16 Jun 2006 13:53:48 -0700, Peter Silva <pe*********@ec.gc.ca> wrote:
Hi folks,

I have a need in a network data distribution application to send out
data to folks who want it using the protocol of their choice. I´d
like it to support a variety of protocols and I don´t want to
implement any of them :-)
http, ftp (via ftplib) , https (dunno how yet), ssl, ssh, sftp (via
paramiko)

The thing is... I want rate-limiting so that in the case of a failure
of a single client
I don´t penalize the other clients, or if my server (which is acting
as a client pushing to remote servers.) goes down, it doesn´t saturate
the link when it comes back.

So I want to have all the protocols limit the number of bytes they send
per second.
It looks like the easiest way to do this is to dive into socket.py...
and look! it says:

# Wrapper module for _socket, providing some additional facilities
# implemented in Python.

note the ´additional facilities implemented in python´ ...

so we just add logic to:
-- add a ´maxrate´ argument to the constructor and/or an attribute to
modify the setting...
-- tally bytes, and time, and know when we are going ´too fast´
-- when too fast.. in the ´flush´ routine, in the synchronous case,
sleep for the correct time to come back under budget. in the async,
return without writing.
-- do something similar for reading.

Anybody think this would be fun?


Use Twisted instead. It supports every protocol you mentioned, and
rate limiting too.

Jean-Paul


Jun 19 '06 #2
Peter Silva <Pe*********@ec.gc.ca> wrote:
I looked at twisted briefly. It looks like it is server oriented.
Does it work in for clients initiating connections?


Twisted supports clients, servers, and "middleware" (proxies etc) in
equally wonderful and powerful ways.
Alex
Jun 20 '06 #3

Cool! Will check it out...

Alex Martelli wrote:
Peter Silva <Pe*********@ec.gc.ca> wrote:
I looked at twisted briefly. It looks like it is server oriented.
Does it work in for clients initiating connections?


Twisted supports clients, servers, and "middleware" (proxies etc) in
equally wonderful and powerful ways.
Alex


Jun 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
0
by: Bob | last post by:
Hi. I'm developed a simple Transfer File program just to test the NetworkStream class. I want to know how can i get the transfer rate speed. Does someone know how to do it? And... what's the size...
2
by: mscdex | last post by:
I have a server application that accepts file transfers (utilitzing tcplistener) and was wondering how I would efficiently go about determining the calculate transfer rate while I am transferring...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
5
by: raghubr | last post by:
Hi all, Can any one pls guide me through..I need to transfer the file from server to client and client to server using sockets in an Asynchronous mode so this file transfer doesn't hinder the...
2
yashg
by: yashg | last post by:
I am building a data backup application in C# using Sockets. It has a server component and a client component. The client is going to upload files to the server through TCP sockets. I've got all...
4
by: Andrew Jackson | last post by:
I am writing a newsgroup client. I have the protocol figured out. But I get slow transfer speeds off any of the network objects read the data from For example one of the commands for a news...
4
by: Dimitrios Apostolou | last post by:
Hello list, I want to limit the download speed when using urllib2. In particular, having several parallel downloads, I want to make sure that their total speed doesn't exceed a maximum value. ...
1
by: diegoblin | last post by:
Hi, i kind of new to java and i want to transfer a file between a server and a client. I know i have to use InputStream and OutputStream, but i don't know how to do it properly. So far i think i've...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.