[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CPS/throttle patches



On Mon, 10 Jun 2002 18:27:17 +0200
Richard Fuchs <dfx@gmx.at> wrote:

> Quick update. There's a new version (0.2) of the CPS patch [1]. The previous
> version reported a slightly incorrect CPS, this is fixed now.
> 
> The per-send throttle patch [2] has also been updated to version 0.2. It is
> now possible to set different CPS limits for different sends. You can do
> that by issuing a command like "/dcc send -maxcps=1500 ..." The maximum CPS
> for each send or get is also reported in the DCC info dialog.
> 
> As promised, the third patch [3] is ready now as well, implementing a
> global DCC throttle, for sends and gets. It is possible to exempt a DCC
> connection from the global limit by giving the DCC a limit of -1 (/dcc send
> -maxcps=-1 ...)
> 
> Also available is a combined patch [4], containing all of the above three
> patches, as well as a completely patched Xchat tarball [5].
> 
> Richard
> 
> PS: Ok, I got a little bored there with all those different versions of the
> patches. So what?

These look pretty good to me. I might put them in 1.9.x to give them a work
out (they should actually apply without too much trouble).

Just a few notes:

1) Could you use xchat coding style? Like
  if () 
  {
  }
  i.e. line up the "{" and  "}" :)

2) gettimeofday() isn't available on win32. We could say, to hell with win32!
   But there's an easy fix:
	GTimeVal timev;
	g_get_current_time (&timev);
   GTimeVal has the same fields as struct timeval;

3) fe_timeout_add (250, dcc_calc_cps_timer, 0);
   Isn't it a bit too intensive for an irc client to be going through
   a list of calculations every 250ms? The DCC GUI is only updated every
   2 seconds anyway (1 second in 1.9.x).

4) Did you try using time(0) instead of gettimeofday(), or was that just
   too coarse?

5) What happens if we receive an Exception (the other end disconnects) while
   the iotag is removed?

+		if (dcc->throttled) {
+			fe_input_remove(dcc->iotag);
+			dcc->iotag = 0;
+			return FALSE;
+		}

It seems to me that the cps calculations could be done alot simpler, without
needing an array of struct timevals. For example, every second, you record the
file position:

time	pos	gain
0	0	0
1	4096	4096
2	8192	4096
3	10000	1808
4	12000	2000
5	17000	5000
6	20000	3000

cps = (4096 + 4096 + 1808 + 2000 + 5000 + 3000) / 6
cps = 3333
sounds about right I think?
Of course, you only keep a record of the last X (10 or 20?) "gains".
Then, if the xfer stalls, you should notice:

time	pos	gain
7	21000	1000
8	21000	0
9	21000	0
10	21000	0

cps = (1000 + 0 + 0 + 0) / 4
cps = 250 (and eventually zero, once the "sliding window" moves beyond
           the gain of 1000).

This way, you only need to keep an array of CPS_NUM_SAMPLES ints:

	int gains[CPS_NUM_SAMPLES];/* bytes received in the last few seconds */
	int index_into_gains;

Ok, now pick holes in my theory :)

-- 
Peter Zelezny.
--
XChat-discuss: mailing list for XChat users
Archive:       http://mail.nl.linux.org/xchat-discuss/