-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi I have started to add bandwidth <limit> option to icecast. My ideea is to compute the current bandwidth by estimation on each sock_write*() call. Something like this: 1. initially we set kbps = 0, kbps_time = now and kbps_bytes = 0 2. after some time, a sock_write*() function is called which in turn calls sock_kbps_update(nobytes); sock_kbps_update fetches current timestamp, adds nobytes to kbps_bytes then: 2.1 if the time difference between now and kbps_time is smaller than ESTIMATION_INTERVAL (which I think a value of 5 seconds should do) then we go back to 2 2.2 if the time difference is greater or equal to ESTIMATION_INTERVAL then we recompute the current kbps by this formula, kbps = (int)(((double)kbps_bytes / (now - kbps_time)) * 8 / 1000) then we store kbps_time = now and reset kbps_bytes = 0 . then go back to 2 I think this is a good solution because all socket writes are done with sock_write*() so we catch them all this way. Problem is that I think I need a mutex on this values (kbps, kbps_time, kbps_bytes) and it seems sock.c didnt use any yet. Whould it be a problem to use one ? (and include thread/thread.h ?) Any other sugestions welcomed. Thanks! - -- Mihai RUSU Email: dizzy@roedu.net GPG : http://dizzy.roedu.net/dizzy-gpg.txt WWW: http://dizzy.roedu.net "Linux is obsolete" -- AST -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFAKlZxPZzOzrZY/1QRAjIlAJ0aEUnnZMO1zqupGSYFZxkF7QdDBACcDWLp FZyelTkdoGpp2GBfUyBGBPY=440c -----END PGP SIGNATURE----- --- >8 ---- List archives: http://www.xiph.org/archives/ icecast project homepage: http://www.icecast.org/ To unsubscribe from this list, send a message to 'icecast-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
> Any other sugestions welcomed. Thanks!Only one. Don't do it like that. Keep a byte counter. Before each sock_write(), first check if we can write without sleeping. I.e if (counter > (maxval * ms)) then we cannot write and have to sleep. maxval is in KiloBytes per second here, and ms is the millisecond fraction of the current second. (i.e from gettimeofday()). counter is in bytes before the write. Instead of sleeping, it's nicer to queue the packet in some priority queue, and have another thread read from that queue and send the packets out at a specified time (sendtime). The sendtime is calculated using (counter/maxval) - ms, and is relative to "now". It could also be used for sleeping. If you choose to queue, add the data_length to counter when you queue the packet, and if you choose to sleep, add data_length to counter when you are done sleeping. This helps keep the code tidy and without ugly locks. You have to keep a timestamp also, to reset the counter to 0 every second. Check that before each write, and not somewhere else (you have to do a gettimeofday() anyway). //Alexander --- >8 ---- List archives: http://www.xiph.org/archives/ icecast project homepage: http://www.icecast.org/ To unsubscribe from this list, send a message to 'icecast-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 12 Feb 2004, Michael Smith wrote:> On Thursday 12 February 2004 03:21, Mihai RUSU wrote: > > I think this is a good solution because all socket writes are done with > > sock_write*() so we catch them all this way. Problem is that I think I > > need a mutex on this values (kbps, kbps_time, kbps_bytes) and it seems > > sock.c didnt use any yet. Whould it be a problem to use one ? (and include > > thread/thread.h ?) > > You must not put this logic into sock.c, since that code is shared by other > code, it's not solely used in icecast. > > Also, sock_write() doesn't have any access to the client structure, so this > wouldn't be a sensible approach anyway.Ok, thanks for answer Mike. Can you sugest a "common" place to catch up every socket write without modifying every source location where icecast calls socket_write*() ? PS: I have also spoken with Karl about this and he has in his latest patches a send_to_client() routine which would offer be a better way for byte counting per source/mountpoint; Im going to look further in his patches about this> Mike- -- Mihai RUSU Email: dizzy@roedu.net GPG : http://dizzy.roedu.net/dizzy-gpg.txt WWW: http://dizzy.roedu.net "Linux is obsolete" -- AST -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFAKyy/PZzOzrZY/1QRAlheAJ45vJ0JpUlBFsaMunuVmlwNIHeb6ACgxI8L WA991WZo4bzrfPl1qTBzoOU=S4T6 -----END PGP SIGNATURE----- --- >8 ---- List archives: http://www.xiph.org/archives/ icecast project homepage: http://www.icecast.org/ To unsubscribe from this list, send a message to 'icecast-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
On Thursday 12 February 2004 03:21, Mihai RUSU wrote:> I think this is a good solution because all socket writes are done with > sock_write*() so we catch them all this way. Problem is that I think I > need a mutex on this values (kbps, kbps_time, kbps_bytes) and it seems > sock.c didnt use any yet. Whould it be a problem to use one ? (and include > thread/thread.h ?)You must not put this logic into sock.c, since that code is shared by other code, it's not solely used in icecast. Also, sock_write() doesn't have any access to the client structure, so this wouldn't be a sensible approach anyway. <p>Mike --- >8 ---- List archives: http://www.xiph.org/archives/ icecast project homepage: http://www.icecast.org/ To unsubscribe from this list, send a message to 'icecast-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.