ons 2003-07-09 klockan 10.16 skrev zulkarnain:
> Hi Henrik,
>
> This is a modifed files of dynamic delay pools for
> squid-2.5stable2 that I got from the internet. Please
> let me know if you could add this as the default
> feature of squid-2.5stable3 release.
Please describe the function of these dynamic delay pools.
Notice: The parse_delay_pool_class initialization changes does not look
right. The old initialization code follows, overriding what you have
done by allocating a new pool.
Also, it is recommended to send changes in "diff -u" format.
diff -ur original-directory new-directory >filename.patch
[diff version of your changes attached]
Regards
Henrik
diff -ru --show-c-function squid-2.5.STABLE2/src/cache_cf.c squid-2.5.STABLE2-ddpool/src/cache_cf.c
--- squid-2.5.STABLE2/src/cache_cf.c 2003-02-06 06:01:07.000000000 +0100
+++ squid-2.5.STABLE2-ddpool/src/cache_cf.c 2003-06-27 07:02:01.000000000 +0200
@@ -1,5 +1,5 @@
-/*
+/*
* $Id: cache_cf.c,v 1.396.2.13 2003/02/06 05:01:07 wessels Exp $
*
* DEBUG: section 3 Configuration File Parsing
@@ -830,7 +830,27 @@ parse_delay_pool_class(delayConfig * cfg
delayFreeDelayPool(pool);
safe_free(cfg->rates[pool]);
}
- /* Allocates a "delaySpecSet" just as large as needed for the class */
+
+/*-------------------------- UoM Modified code --------------------------------------------------------- */
+ cfg->rates[pool] = xmalloc(class * sizeof(delaySpec));
+ cfg->class[pool] = class;
+ cfg->rates[pool]->aggregate.restore_bps = cfg->rates[pool]->aggregate.max_bytes = -1;
+ cfg->rates[pool]->aggregate.restore_bps_orig = cfg->rates[pool]->aggregate.max_bytes_orig = -1;
+
+ if (cfg->class[pool] >= 3)
+ {
+ cfg->rates[pool]->network.restore_bps = cfg->rates[pool]->network.max_bytes = -1;
+ cfg->rates[pool]->network.restore_bps_orig = cfg->rates[pool]->network.max_bytes_orig = -1;
+ }
+
+ if (cfg->class[pool] >= 2)
+ {
+ cfg->rates[pool]->individual.restore_bps = cfg->rates[pool]->individual.max_bytes = -1;
+ cfg->rates[pool]->individual.restore_bps_orig = cfg->rates[pool]->individual.max_bytes_orig = -1;
+ }
+/*-------------------------- UoM Modified code ---------------------------------------------------------- */
+
+ /* Allocates a "delaySpecSet" just as large as needed for the class */
cfg->rates[pool] = xmalloc(class * sizeof(delaySpec));
cfg->class[pool] = class;
cfg->rates[pool]->aggregate.restore_bps = cfg->rates[pool]->aggregate.max_bytes = -1;
@@ -869,8 +889,12 @@ parse_delay_pool_rates(delayConfig * cfg
if (sscanf(token, "%d", &i) != 1)
self_destruct();
ptr->restore_bps = i;
- i = GetInteger();
- ptr->max_bytes = i;
+/*-------------------------- UoM Modified code --------------------------------------- */
+ ptr->restore_bps_orig = i;
+ i = GetInteger();
+ ptr->max_bytes = i;
+ ptr->max_bytes_orig = i;
+/*-------------------------- UoM Modified code --------------------------------------- */
ptr++;
}
class = cfg->class[pool];
diff -ru --show-c-function squid-2.5.STABLE2/src/delay_pools.c squid-2.5.STABLE2-ddpool/src/delay_pools.c
--- squid-2.5.STABLE2/src/delay_pools.c 2003-03-09 19:41:27.000000000 +0100
+++ squid-2.5.STABLE2-ddpool/src/delay_pools.c 2003-06-27 07:02:07.000000000 +0200
@@ -67,13 +67,29 @@ struct _class3DelayPool {
unsigned char network_map[NET_MAP_SZ];
unsigned char network_255_used;
/* 256 entries */
- int network[256];
+ int network[256];
+
+ // ---------- UoM modification --------------------------------------------------------
+ // we need to keep separate values for each network in order to
+ // manage the bandwidth control
+ int network_restore_bps[NET_MAP_SZ];
+ int network_max_bytes[NET_MAP_SZ];
+ // ---------- end of modification -----------------------------------------------------
+
/* 256 sets of (255 entries + 1 terminator byte) */
unsigned char individual_map[NET_MAP_SZ][IND_MAP_SZ];
/* Pack this into one bit per net */
unsigned char individual_255_used[32];
/* largest entry = (255<<8)+255 = 65535 */
int individual[C3_IND_SZ];
+
+ // ---------- UoM modification --------------------------------------------------------
+ // we need to keep separate values for each individual in order to
+ // manage the bandwidth control
+ int individual_restore_bps[C3_IND_SZ];
+ int individual_max_bytes[C3_IND_SZ];
+ // ---------- end of modification -----------------------------------------------------
+
};
typedef struct _class1DelayPool class1DelayPool;
@@ -88,14 +104,27 @@ union _delayPool {
typedef union _delayPool delayPool;
+// ------------------------ UoM modifications ---------------------------------------------------
+#define DOWN_GRADE 0.95
+#define UP_GRADE 0.02
+// ------------------- end of modification ------------------------------------------------------
+
static delayPool *delay_data = NULL;
static fd_set delay_no_delay;
static time_t delay_pools_last_update = 0;
static hash_table *delay_id_ptr_hash = NULL;
static long memory_used = 0;
+static long int excess_bytes = 0; // UoM addition
static OBJH delayPoolStats;
+// ------------------------ UoM modifications ---------------------------------------------------
+static void delayPoolsRestoreUpdate(void *unused);
+static void delayUpdateRestoreClass1(class1DelayPool * class1, delaySpecSet * rates, int incr, int class_num);
+static void delayUpdateRestoreClass3(class3DelayPool * class3, delaySpecSet * rates, int incr, int class_num);
+static time_t RestoreVal_last_update = 0;
+// ------------------- end of modification ------------------------------------------------------
+
static unsigned int
delayIdPtrHash(const void *key, unsigned int n)
{
@@ -146,6 +175,8 @@ delayInitDelayData(unsigned short pools)
delay_data = xcalloc(pools, sizeof(*delay_data));
memory_used += pools * sizeof(*delay_data);
eventAdd("delayPoolsUpdate", delayPoolsUpdate, NULL, 1.0, 1);
+ eventAdd("delayPoolsRestoreUpdate", delayPoolsRestoreUpdate, NULL, 1.0, 1); //UoM addition
+ excess_bytes = 0; //UoM addition
delay_id_ptr_hash = hash_create(delayIdPtrHashCmp, 256, delayIdPtrHash);
}
@@ -235,6 +266,9 @@ delayInitDelayPool(unsigned short pool,
/* delaySetSpec may be pointer to partial structure so MUST pass by
* reference.
*/
+
+ int i=0;
+
switch (class) {
case 1:
delay_data[pool].class1->aggregate = (int) (((double) rates->aggregate.max_bytes *
@@ -253,6 +287,22 @@ delayInitDelayPool(unsigned short pool,
delay_data[pool].class3->network_255_used = 0;
memset(&delay_data[pool].class3->individual_255_used, '\0',
sizeof(delay_data[pool].class3->individual_255_used));
+
+ // ------------------ UoM modification ---------------------------------------------------
+ /* initialize the network and individual restore value variables */
+ for (i = 0; i < NET_MAP_SZ; i++)
+ {
+ delay_data[pool].class3->network_restore_bps[i] = rates->network.restore_bps;
+ delay_data[pool].class3->network_max_bytes[i] = rates->network.max_bytes;
+ }
+
+ for (i = 0; i < C3_IND_SZ; i++)
+ {
+ delay_data[pool].class3->individual_restore_bps[i] = rates->individual.restore_bps;
+ delay_data[pool].class3->individual_max_bytes[i] = rates->individual.max_bytes;
+ }
+ // ------------------ end of modification ------------------------------------------------
+
break;
default:
assert(0);
@@ -401,6 +451,7 @@ delayClient(clientHttpRequest * http)
delay_data[pool].class3->individual[position] =
(int) (((double) Config.Delay.rates[pool]->individual.max_bytes *
Config.Delay.initial) / 100);
+ delay_data[pool].class3->individual_restore_bps[position] = delay_data[pool].class3->individual_restore_bps[0];
}
return delayId(pool + 1, position);
}
@@ -419,6 +470,7 @@ delayClient(clientHttpRequest * http)
delay_data[pool].class3->individual[position] =
(int) (((double) Config.Delay.rates[pool]->individual.max_bytes *
Config.Delay.initial) / 100);
+ delay_data[pool].class3->individual_restore_bps[position] = delay_data[pool].class3->individual_restore_bps[0];
break;
}
}
@@ -467,84 +519,189 @@ delayUpdateClass2(class2DelayPool * clas
}
}
-static void
-delayUpdateClass3(class3DelayPool * class3, delaySpecSet * rates, int incr)
-{
+// --------------------- this function modified by UoM ---------------------------------
+static void delayUpdateClass3(class3DelayPool * class3, delaySpecSet * rates, int incr, long int * excess_bytes, unsigned long * max_bandwidth)
+ {
int individual_restore_bytes, network_restore_bytes;
int mpos;
- unsigned char i, j; /* depends on 255 + 1 = 0 */
- /* delaySetSpec may be pointer to partial structure so MUST pass by
- * reference.
- */
- if (rates->aggregate.restore_bps != -1 &&
- (class3->aggregate += rates->aggregate.restore_bps * incr) >
- rates->aggregate.max_bytes)
- class3->aggregate = rates->aggregate.max_bytes;
- /* the following line deliberately uses &, not &&, in an if statement
- * to avoid conditional execution
- */
- if (((network_restore_bytes = rates->network.restore_bps) == -1) &
- ((individual_restore_bytes = rates->individual.restore_bps) == -1))
- return;
- individual_restore_bytes *= incr;
- network_restore_bytes *= incr;
- /* i < NET_MAP_SZ is enforced by data type (unsigned chars are all < 256).
- * this loop starts at 0 or 255 and ends at 254 unless terminated earlier
- * by finding the end of the map. note as above that 255 + 1 = 0.
- */
- for (i = (class3->network_255_used ? 0 : 255);; ++i) {
- if (i != 255 && class3->network_map[i] == 255)
- return;
- if (individual_restore_bytes != -incr) {
- mpos = i << 8;
- /* this is not as simple as the outer loop as mpos doesn't wrap like
- * i and j do. so the net 255 increment is done as a separate special
- * case. the alternative would be overlapping a union of two chars on
- * top of a 16-bit unsigned int, but that wouldn't really be worth the
- * effort.
- */
- for (j = 0;; ++j, ++mpos) {
- if (class3->individual_map[i][j] == 255)
- break;
- assert(mpos < C3_IND_SZ);
- if (class3->individual[mpos] != rates->individual.max_bytes &&
- (class3->individual[mpos] += individual_restore_bytes) >
- rates->individual.max_bytes)
- class3->individual[mpos] = rates->individual.max_bytes;
- if (j == 254)
- break;
- }
- if (class3->individual_255_used[i / 8] & (1 << (i % 8))) {
- mpos |= 255; /* this will set mpos to network 255 */
- assert(mpos < C3_IND_SZ);
- if (class3->individual[mpos] != rates->individual.max_bytes &&
- (class3->individual[mpos] += individual_restore_bytes) >
- rates->individual.max_bytes)
- class3->individual[mpos] = rates->individual.max_bytes;
- }
- }
- if (network_restore_bytes != -incr &&
- class3->network[i] != rates->network.max_bytes &&
- (class3->network[i] += network_restore_bytes) >
- rates->network.max_bytes)
- class3->network[i] = rates->network.max_bytes;
- if (i == 254)
- return;
- }
-}
+ unsigned char i, j; // depends on 255 + 1 = 0
+// delaySetSpec may be pointer to partial structure so MUST pass by reference.
+ if (rates->aggregate.restore_bps != -1)
+ *max_bandwidth += rates->aggregate.restore_bps;
+
+ if (rates->aggregate.restore_bps != -1 && (class3->aggregate += rates->aggregate.restore_bps * incr) >
+ rates->aggregate.max_bytes)
+ {
+ *excess_bytes += (class3->aggregate - rates->aggregate.max_bytes);
+ class3->aggregate = rates->aggregate.max_bytes;
+
+ debug(77, 2) ("DelayUpdateClass3: Excess_bytes=%d, C3 Aggregate=%d, Max_bytes=%d, incr=%d\n", *excess_bytes, class3->aggregate, rates->aggregate.max_bytes, incr );
+ }
+ else
+ {
+ if ((class3->aggregate < rates->aggregate.max_bytes) && (*excess_bytes > 0))
+ {
+ if (*excess_bytes > (rates->aggregate.max_bytes - class3->aggregate))
+ {
+ *excess_bytes -= (rates->aggregate.max_bytes - class3->aggregate);
+ class3->aggregate = rates->aggregate.max_bytes;
+ }
+ else
+ {
+ class3->aggregate += *excess_bytes;
+ *excess_bytes = 0;
+ }
+ }
+ debug(77, 2) ("DelayUpdateClass3: Excess_bytes=%d, C3 Aggregate=%d, Max_bytes=%d\n", *excess_bytes, class3->aggregate, rates->aggregate.max_bytes );
+ }
+// the following line deliberately uses &, not &&, in an if statement to avoid conditional execution
+
+ if (((network_restore_bytes = rates->network.restore_bps) == -1) &
+ ((individual_restore_bytes = rates->individual.restore_bps) == -1))
+ return;
+
+ individual_restore_bytes *= incr;
+ network_restore_bytes *= incr;
+
+// i < NET_MAP_SZ is enforced by data type (unsigned chars are all < 256)
+// this loop starts at 0 or 255 and ends at 254 unless terminated earlier
+// by finding the end of the map. note as above that 255 + 1 = 0.
+
+ for (i = (class3->network_255_used ? 0 : 255);; ++i)
+ {
+ if (i != 255 && class3->network_map[i] == 255)
+ return;
+
+ if (individual_restore_bytes != -incr)
+ {
+ mpos = i << 8;
+// this is not as simple as the outer loop as mpos doesn't wrap like
+// i and j do. so the net 255 increment is done as a separate special
+// case. the alternative would be overlapping a union of two chars on
+// top of a 16-bit unsigned int, but that wouldn't really be worth the
+// effort.
+
+ for (j = 0;; ++j, ++mpos)
+ {
+ if (class3->individual_map[i][j] == 255)
+ break;
+
+ assert(mpos < C3_IND_SZ);
+ if (class3->individual[mpos] != rates->individual.max_bytes &&
+ (class3->individual[mpos] += (class3->individual_restore_bps[mpos] * incr)) >
+ rates->individual.max_bytes)
+ class3->individual[mpos] = rates->individual.max_bytes;
+
+ if (j == 254)
+ break;
+ }
+
+ if (class3->individual_255_used[i / 8] & (1 << (i % 8)))
+ {
+ mpos |= 255; // this will set mpos to network 255
+ assert(mpos < C3_IND_SZ);
+ if (class3->individual[mpos] != rates->individual.max_bytes &&
+ (class3->individual[mpos] += (class3->individual_restore_bps[mpos] * incr)) >
+ rates->individual.max_bytes)
+
+ class3->individual[mpos] = rates->individual.max_bytes;
+ }
+ }
+
+ if (network_restore_bytes != -incr && class3->network[i] != rates->network.max_bytes &&
+ (class3->network[i] += (class3->network_restore_bps[i] * incr)) > rates->network.max_bytes)
+ class3->network[i] = rates->network.max_bytes;
+
+ if (i == 254)
+ return;
+ }
+ }
+// ----------------------------- end of UoM modified function --------------------------------------------
+
+// --------------------- this function modified by UoM ---------------------------------
+//static void
+//delayUpdateClass3(class3DelayPool * class3, delaySpecSet * rates, int incr)
+//{
+// int individual_restore_bytes, network_restore_bytes;
+// int mpos;
+// unsigned char i, j; /* depends on 255 + 1 = 0 */
+// // delaySetSpec may be pointer to partial structure so MUST pass by
+// // reference.
+// //
+// if (rates->aggregate.restore_bps != -1 &&
+// (class3->aggregate += rates->aggregate.restore_bps * incr) >
+// rates->aggregate.max_bytes)
+// class3->aggregate = rates->aggregate.max_bytes;
+// // the following line deliberately uses &, not &&, in an if statement
+// // to avoid conditional execution
+// //
+// if (((network_restore_bytes = rates->network.restore_bps) == -1) &
+// ((individual_restore_bytes = rates->individual.restore_bps) == -1))
+// return;
+// individual_restore_bytes *= incr;
+// network_restore_bytes *= incr;
+// // i < NET_MAP_SZ is enforced by data type (unsigned chars are all < 256).
+// // this loop starts at 0 or 255 and ends at 254 unless terminated earlier
+// // by finding the end of the map. note as above that 255 + 1 = 0.
+// //
+// for (i = (class3->network_255_used ? 0 : 255);; ++i) {
+// if (i != 255 && class3->network_map[i] == 255)
+// return;
+// if (individual_restore_bytes != -incr) {
+// mpos = i << 8;
+// // this is not as simple as the outer loop as mpos doesn't wrap like
+// // i and j do. so the net 255 increment is done as a separate special
+// // case. the alternative would be overlapping a union of two chars on
+// // top of a 16-bit unsigned int, but that wouldn't really be worth the
+// // effort.
+// //
+// for (j = 0;; ++j, ++mpos) {
+// if (class3->individual_map[i][j] == 255)
+// break;
+// assert(mpos < C3_IND_SZ);
+// if (class3->individual[mpos] != rates->individual.max_bytes &&
+// (class3->individual[mpos] += individual_restore_bytes) >
+// rates->individual.max_bytes)
+// class3->individual[mpos] = rates->individual.max_bytes;
+// if (j == 254)
+// break;
+// }
+// if (class3->individual_255_used[i / 8] & (1 << (i % 8))) {
+// mpos |= 255; // this will set mpos to network 255
+// assert(mpos < C3_IND_SZ);
+// if (class3->individual[mpos] != rates->individual.max_bytes &&
+// (class3->individual[mpos] += individual_restore_bytes) >
+// rates->individual.max_bytes)
+// class3->individual[mpos] = rates->individual.max_bytes;
+// }
+// }
+// if (network_restore_bytes != -incr &&
+// class3->network[i] != rates->network.max_bytes &&
+// (class3->network[i] += network_restore_bytes) >
+// rates->network.max_bytes)
+// class3->network[i] = rates->network.max_bytes;
+// if (i == 254)
+// return;
+// }
+//}
+// ----------------------------- end of UoM modified function --------------------------------------------
+
void
delayPoolsUpdate(void *unused)
{
int incr = squid_curtime - delay_pools_last_update;
unsigned short i;
unsigned char class;
+ unsigned long int max_bandwidth;
+
if (!Config.Delay.pools)
return;
eventAdd("delayPoolsUpdate", delayPoolsUpdate, NULL, 1.0, 1);
if (incr < 1)
return;
delay_pools_last_update = squid_curtime;
+ max_bandwidth = 0;
for (i = 0; i < Config.Delay.pools; i++) {
class = Config.Delay.class[i];
if (!class)
@@ -557,12 +714,14 @@ delayPoolsUpdate(void *unused)
delayUpdateClass2(delay_data[i].class2, Config.Delay.rates[i], incr);
break;
case 3:
- delayUpdateClass3(delay_data[i].class3, Config.Delay.rates[i], incr);
+ delayUpdateClass3(delay_data[i].class3, Config.Delay.rates[i], incr, & excess_bytes, & max_bandwidth);
break;
default:
assert(0);
}
}
+ if (excess_bytes > (max_bandwidth * 5))
+ excess_bytes = (max_bandwidth * 5);
}
/*
@@ -622,12 +781,23 @@ delayBytesIn(delay_id d, int qty)
unsigned short pool = (d >> 16) - 1;
unsigned char class;
+ int old_aggregate_val=0;//UoM Addition
+ int old_network_val = 0;
+ int old_individual_val = 0;
+
if (pool == 0xFFFF)
return;
class = Config.Delay.class[pool];
switch (class) {
case 1:
- delay_data[pool].class1->aggregate -= qty;
+ old_aggregate_val = delay_data[pool].class1->aggregate;
+ delay_data[pool].class1->aggregate -= qty;
+
+// ------------------------ UoM modification ------------------------------------------------------
+ debug(77, 3) ("DelayBytesIn: Class1 Num=%d, Old Aggregate=%d, Qty In=%d New Aggregate=%d\n",
+ (pool + 1), old_aggregate_val, qty, delay_data[pool].class1->aggregate);
+// ------------------------------------------------------------------------------------------------
+
return;
case 2:
delay_data[pool].class2->aggregate -= qty;
@@ -637,6 +807,17 @@ delayBytesIn(delay_id d, int qty)
delay_data[pool].class3->aggregate -= qty;
delay_data[pool].class3->network[position >> 8] -= qty;
delay_data[pool].class3->individual[position] -= qty;
+
+// ------------------------ UoM modification ------------------------------------------------------
+/* debug(77, 3) ("DelayBytesIn: Class3 Num=%d, Network ID=%d, Individual ID=%d\n", (pool + 1), (position >> 8), position);
+ debug(77, 3) ("\t\tOld Aggregate=%d,\tQty In=%d,\tNew Aggregate=%d\n",
+ old_aggregate_val, qty, delay_data[pool].class3->aggregate );
+ debug(77, 3) ("\t\tOld Network=%d,\tQty In=%d,\tNew Network=%d\n",
+ old_network_val, qty, delay_data[pool].class3->network[position >> 8]);
+ debug(77, 3) ("\t\tOld Individual=%d,\tQty In=%d\tNew Individual=%d\n",
+ old_individual_val, qty,delay_data[pool].class3->individual[position]);*/
+// ------------------------------------------------------------------------------------------------
+
return;
}
fatalf("delayBytesWanted: Invalid class %d\n", class);
@@ -774,12 +955,15 @@ delayPoolStats3(StoreEntry * sentry, uns
for (i = 0; i < NET_MAP_SZ; i++) {
if (class3->network_map[i] == 255)
break;
- storeAppendPrintf(sentry, "%d:%d ", class3->network_map[i],
- class3->network[i]);
+ //storeAppendPrintf(sentry, "%d:%d ", class4->network_map[i],
+ // class3->network[i]); --------- Old code
+ storeAppendPrintf(sentry, "%d:%d [R=%d] ", class3->network_map[i], class3->network[i], class3->network_restore_bps[i]);
+
shown = 1;
}
if (class3->network_255_used) {
- storeAppendPrintf(sentry, "%d:%d ", 255, class3->network[255]);
+ // storeAppendPrintf(sentry, "%d:%d ", 255, class3->network[255]);Old Code
+ storeAppendPrintf(sentry, "%d:%d [R=%d] ", 255, class3->network[255], class3->network_restore_bps[255]);
shown = 1;
}
if (!shown)
@@ -802,11 +986,13 @@ delayPoolStats3(StoreEntry * sentry, uns
for (j = 0; j < IND_MAP_SZ; j++) {
if (class3->individual_map[i][j] == 255)
break;
- storeAppendPrintf(sentry, "%d:%d ", class3->individual_map[i][j],
- class3->individual[(i << 8) | j]);
+ // storeAppendPrintf(sentry, "%d:%d ", class3->individual_map[i][j],
+ // class3->individual[(i << 8) | j]); Old Code
+ storeAppendPrintf(sentry, "%d:%d [R=%d] ", class3->individual_map[i][j], class3->individual[(i << 8) | j], class3->individual_restore_bps[(i << 8) | j]);
}
if (class3->individual_255_used[i / 8] & (1 << (i % 8))) {
- storeAppendPrintf(sentry, "%d:%d ", 255, class3->individual[(i << 8) | 255]);
+ //storeAppendPrintf(sentry, "%d:%d ", 255, class3->individual[(i << 8) | 255]);Old Code
+ storeAppendPrintf(sentry, "%d:%d [R=%d] ", 255, class3->individual[(i << 8) | 255], class3->individual_restore_bps[(i << 8) | 255]);
}
storeAppendPrintf(sentry, "\n");
}
@@ -816,11 +1002,15 @@ delayPoolStats3(StoreEntry * sentry, uns
for (j = 0; j < IND_MAP_SZ; j++) {
if (class3->individual_map[255][j] == 255)
break;
- storeAppendPrintf(sentry, "%d:%d ", class3->individual_map[255][j],
- class3->individual[(255 << 8) | j]);
+ // storeAppendPrintf(sentry, "%d:%d ", class3->individual_map[255][j],
+ // class3->individual[(255 << 8) | j]);
+ storeAppendPrintf(sentry, "%d:%d [R=%d] ", class3->individual_map[255][j], class3->individual[(255 << 8) | j], class3->individual_restore_bps[(255 << 8) | j]);
+
}
if (class3->individual_255_used[255 / 8] & (1 << (255 % 8))) {
- storeAppendPrintf(sentry, "%d:%d ", 255, class3->individual[(255 << 8) | 255]);
+ //storeAppendPrintf(sentry, "%d:%d ", 255, class3->individual[(255 << 8) | 255]); Old Code
+ storeAppendPrintf(sentry, "%d:%d [R=d%] ", 255, class3->individual[(255 << 8) | 255], class3->individual_restore_bps[(255 << 8) | 255]);
+
}
storeAppendPrintf(sentry, "\n");
}
@@ -857,4 +1047,261 @@ delayPoolStats(StoreEntry * sentry)
storeAppendPrintf(sentry, "Memory Used: %d bytes\n", (int) memory_used);
}
+// ---------------------------- Source code modfications at UOM begins here ----------------------------------------
+// -----------------------------------------------------------------------------------------------------------------
+
+// main function for updating the restore values of the delay pool
+static void delayPoolsRestoreUpdate(void *unused)
+ {
+ unsigned short i;
+ unsigned char class;
+
+ int incr = squid_curtime - RestoreVal_last_update;
+ if (!Config.Delay.pools)
+ return;
+
+ eventAdd("delayPoolsRestoreUpdate", delayPoolsRestoreUpdate, NULL, 1.0, 1);
+ if (incr < 1)
+ return;
+
+ for (i = 0; i < Config.Delay.pools; i++)
+ {
+ class = Config.Delay.class[i];
+ if (!class)
+ continue;
+
+ switch (class)
+ {
+ case 1:
+ delayUpdateRestoreClass1(delay_data[i].class1, Config.Delay.rates[i], incr, (i + 1));
+ break;
+/* case 2:
+ delayUpdateClass2(delay_data[i].class2, Config.Delay.rates[i], incr);
+ break;*/
+ case 3:
+ delayUpdateRestoreClass3(delay_data[i].class3, Config.Delay.rates[i], incr, (i + 1));
+ break;
+/* default:
+ assert(0);*/
+ }
+ }
+ }
+
+
+static void delayUpdateRestoreClass1(class1DelayPool * class1, delaySpecSet * rates, int incr, int class_num)
+ {
+ /* delaySetSpec may be pointer to partial structure so MUST pass by
+ * reference.
+ */
+
+ int temp_restore_val = 0;
+ int old_restore_val = 0;
+
+ if (rates->aggregate.restore_bps != -1)
+ {
+ old_restore_val = rates->aggregate.restore_bps;
+ if (class1->aggregate < 0)
+ {
+ rates->aggregate.restore_bps = rates->aggregate.restore_bps * DOWN_GRADE;
+ if (rates->aggregate.restore_bps < rates->aggregate.restore_bps_orig)
+ rates->aggregate.restore_bps = rates->aggregate.restore_bps_orig;
+ }
+ /*if (class1->aggregate == 0)
+ {
+ rates->aggregate.restore_bps = rates->aggregate.restore_bps * 0.75;
+ if (rates->aggregate.restore_bps < rates->aggregate.restore_bps_orig)
+ rates->aggregate.restore_bps = rates->aggregate.restore_bps_orig;
+ }*/
+ if ((class1->aggregate > 0) || (class1->aggregate == 0))
+ {
+ temp_restore_val = (int)(rates->aggregate.restore_bps * (1.0 + (class1->aggregate / rates->aggregate.max_bytes)));
+ rates->aggregate.restore_bps = (rates->aggregate.restore_bps * 0.9) + (temp_restore_val * 0.1);
+ if (rates->aggregate.restore_bps > rates->aggregate.max_bytes)
+ rates->aggregate.restore_bps = rates->aggregate.max_bytes;
+ }
+ }
+
+ debug(77, 3) ("Restore Calc: Class1 Num=%d, Max Bytes=%d, Current Val=%d, Old Restore=%d, New Restore=%d Orig Restore=%d\n",
+ class_num, rates->aggregate.max_bytes, class1->aggregate, old_restore_val, rates->aggregate.restore_bps, rates->aggregate.restore_bps_orig);
+ }
+
+
+// calculate the new restore values for a Class 3 delay pool and update the current values
+static void delayUpdateRestoreClass3(class3DelayPool * class3, delaySpecSet * rates, int incr, int class_num)
+ {
+ unsigned int i, j;
+ float temp_aggregate;
+ float temp_max_bytes;
+ float temp_restore;
+
+ int old_restore_val = 0;
+ int toggle_max = 0;
+ int mpos = 0;
+
+ debug(77, 3) ("Restore Calc: Class3 Num=%d\n", class_num );
+ debug(77, 3) ("\t\tAggregate: Max_Bytes=%d, Current_Agg=%d, Restore_Val=%d\n",
+ rates->aggregate.max_bytes, class3->aggregate, rates->aggregate.restore_bps);
+ toggle_max = (int)(rates->aggregate.max_bytes / 10);
+
+
+ //------------- update the network value -------------------------------------------------------------
+ /* the following line deliberately uses &, not &&, in an if statement
+ * to avoid conditional execution
+ */
+
+ if (rates->network.restore_bps == -1)
+ {
+ debug(77, 3) ("\t\tNetwork: Disabled\n");
+ }
+ else
+ {
+ debug(77, 3) ("\t\tNetwork: Values are ignored in dynamic calculations\n");
+ }
+
+ // ------------------------- if individual values are disabled exit function from here -------------------------
+ if (rates->individual.restore_bps == -1)
+ {
+ debug(77, 3) ("\t\tIndividual Disabled.");
+ return;
+ }
+
+ for (i = 0; i < NET_MAP_SZ; i++)
+ {
+ if (class3->network_map[i] == 255)
+ break;
+
+ for (j = 0; j < IND_MAP_SZ; j++)
+ {
+ if (class3->individual_map[i][j] == 255)
+ break;
+
+ mpos = (i << 8) | j;
+ // ---------------- calculate the new individual restore values --------------------------------------
+ old_restore_val = class3->individual_restore_bps[mpos];
+ if (class3->aggregate < toggle_max )
+ {
+ class3->individual_restore_bps[mpos] = class3->individual_restore_bps[mpos] * DOWN_GRADE;
+ if (class3->individual_restore_bps[mpos] < rates->individual.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->individual.restore_bps;
+ }
+
+ if (class3->aggregate >= toggle_max)
+ {
+ temp_restore = class3->individual_restore_bps[mpos];
+ temp_max_bytes = rates->aggregate.max_bytes;
+ temp_aggregate = class3->aggregate;
+
+ temp_restore = temp_restore * (1.0 + (UP_GRADE * (temp_aggregate / temp_max_bytes)));
+ class3->individual_restore_bps[mpos] = temp_restore;
+ if (class3->individual_restore_bps[mpos] > rates->aggregate.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->aggregate.restore_bps;
+ }
+
+ debug(77, 3) ("\t\tIndividual ID=%d, Max Bytes=%d, Current Agg=%d, Old Restore=%d, New Restore=%d Orig Restore=%d\n",
+ class3->individual_map[i][j], class3->individual_max_bytes[mpos], class3->individual[mpos], old_restore_val, class3->individual_restore_bps[mpos], rates->individual.restore_bps_orig);
+
+ }
+
+ if (class3->individual_255_used[i / 8] & (1 << (i % 8)))
+ {
+
+ // ---------------- calculate the new individual restore values --------------------------------------
+ old_restore_val = class3->individual_restore_bps[mpos];
+ if (class3->aggregate < toggle_max )
+ {
+ class3->individual_restore_bps[mpos] = class3->individual_restore_bps[mpos] * DOWN_GRADE;
+ if (class3->individual_restore_bps[mpos] < rates->individual.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->individual.restore_bps;
+ }
+
+ if (class3->aggregate >= toggle_max)
+ {
+ temp_restore = class3->individual_restore_bps[mpos];
+ temp_max_bytes = rates->aggregate.max_bytes;
+ temp_aggregate = class3->aggregate;
+
+ temp_restore = temp_restore * (1.0 + (UP_GRADE * (temp_aggregate / temp_max_bytes)));
+ class3->individual_restore_bps[mpos] = temp_restore;
+ if (class3->individual_restore_bps[mpos] > rates->aggregate.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->aggregate.restore_bps;
+ }
+
+ debug(77, 3) ("\t\tIndividual ID=%d, Max Bytes=%d, Current Agg=%d, Old Restore=%d, New Restore=%d Orig Restore=%d\n",
+ class3->individual_map[i][j], class3->individual_max_bytes[mpos], class3->individual[mpos], old_restore_val, class3->individual_restore_bps[mpos], rates->individual.restore_bps_orig);
+
+ }
+ }
+
+ debug(77, 2) ("\t\tPool aggregate=%d, individual_restore_val=%d\n", class3->aggregate, class3->individual_restore_bps[1]);
+
+ if (class3->network_255_used)
+ {
+ for (j = 0; j < IND_MAP_SZ; j++)
+ {
+ if (class3->individual_map[255][j] == 255)
+ break;
+
+ // ---------------- calculate the new individual restore values --------------------------------------
+ old_restore_val = class3->individual_restore_bps[mpos];
+ if (class3->aggregate < toggle_max )
+ {
+ class3->individual_restore_bps[mpos] = class3->individual_restore_bps[mpos] * DOWN_GRADE;
+ if (class3->individual_restore_bps[mpos] < rates->individual.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->individual.restore_bps;
+ }
+
+ if (class3->aggregate >= toggle_max)
+ {
+ temp_restore = class3->individual_restore_bps[mpos];
+ temp_max_bytes = rates->aggregate.max_bytes;
+ temp_aggregate = class3->aggregate;
+
+ temp_restore = temp_restore * (1.0 + (UP_GRADE * (temp_aggregate / temp_max_bytes)));
+ class3->individual_restore_bps[mpos] = temp_restore;
+ if (class3->individual_restore_bps[mpos] > rates->aggregate.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->aggregate.restore_bps;
+ }
+
+ debug(77, 3) ("\t\tIndividual ID=%d, Max Bytes=%d, Current Agg=%d, Old Restore=%d, New Restore=%d Orig Restore=%d\n",
+ class3->individual_map[i][j], class3->individual_max_bytes[mpos], class3->individual[mpos], old_restore_val, class3->individual_restore_bps[mpos], rates->individual.restore_bps_orig);
+
+ }
+
+ if (class3->individual_255_used[255 / 8] & (1 << (255 % 8)))
+ {
+
+ // ---------------- calculate the new individual restore values --------------------------------------
+ old_restore_val = class3->individual_restore_bps[mpos];
+ if (class3->aggregate < toggle_max )
+ {
+ class3->individual_restore_bps[mpos] = class3->individual_restore_bps[mpos] * DOWN_GRADE;
+ if (class3->individual_restore_bps[mpos] < rates->individual.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->individual.restore_bps;
+ }
+
+ if (class3->aggregate >= toggle_max)
+ {
+ temp_restore = class3->individual_restore_bps[mpos];
+ temp_max_bytes = rates->aggregate.max_bytes;
+ temp_aggregate = class3->aggregate;
+
+ temp_restore = temp_restore * (1.0 + (UP_GRADE * (temp_aggregate / temp_max_bytes)));
+ class3->individual_restore_bps[mpos] = temp_restore;
+ if (class3->individual_restore_bps[mpos] > rates->aggregate.restore_bps)
+ class3->individual_restore_bps[mpos] = rates->aggregate.restore_bps;
+ }
+
+ debug(77, 3) ("\t\tIndividual ID=%d, Max Bytes=%d, Current Agg=%d, Old Restore=%d, New Restore=%d Orig Restore=%d\n",
+ class3->individual_map[i][j], class3->individual_max_bytes[mpos], class3->individual[mpos], old_restore_val, class3->individual_restore_bps[mpos], rates->individual.restore_bps_orig);
+
+
+ }
+ }
+ }
+
+
+
+
+// ---------------------------- end of source code modfications ---------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------------
#endif
diff -ru --show-c-function squid-2.5.STABLE2/src/structs.h squid-2.5.STABLE2-ddpool/src/structs.h
--- squid-2.5.STABLE2/src/structs.h 2003-01-21 01:06:39.000000000 +0100
+++ squid-2.5.STABLE2-ddpool/src/structs.h 2003-06-27 07:02:14.000000000 +0200
@@ -344,10 +344,20 @@ struct _https_port_list {
#endif
#if DELAY_POOLS
-struct _delaySpec {
+/*---------------------- UoM Modified code ----------------------------------------- */
+struct _delaySpec
+ {
int restore_bps;
int max_bytes;
-};
+ int restore_bps_orig;
+ int max_bytes_orig;
+ };
+
+//struct _delaySpec {
+// int restore_bps;
+// int max_bytes;
+//};
+/*---------------------- UoM Modified code ----------------------------------------- */
/* malloc()'d only as far as used (class * sizeof(delaySpec)!
* order of elements very important!