| Index: trunk/extensions/icpagent/icpagent.c |
| — | — | @@ -203,17 +203,15 @@ |
| 204 | 204 | int c; |
| 205 | 205 | icp_opcode opcode=ICP_HIT; |
| 206 | 206 | float t=5.0; |
| 207 | | - int t_int; |
| 208 | | - int t_adjust; |
| 209 | | - int frac; |
| 210 | | - int tenloop = 0; |
| 211 | | - int slow_c = 0; |
| 212 | | - float step = 0; |
| 213 | | - float stepsum = 0; |
| | 207 | + int t_int, t_adjust, frac; |
| | 208 | + // only answer the nth query |
| | 209 | + int replynth = 1; |
| | 210 | + // the loop counter |
| | 211 | + int maincount = 0, step = 0, stepsum = 0; |
| 214 | 212 | struct rlimit rlim; |
| 215 | 213 | |
| 216 | 214 | /* Work with command line options */ |
| 217 | | - while ((c = getopt(ac,av,"dmt:p:cn:")) != -1) { |
| | 215 | + while ((c = getopt(ac,av,"dmr:t:p:cn:")) != -1) { |
| 218 | 216 | switch (c) { |
| 219 | 217 | case 'p': |
| 220 | 218 | /* Port to bind at */ |
| — | — | @@ -236,12 +234,16 @@ |
| 237 | 235 | /* Predefined timeout value */ |
| 238 | 236 | t=atof(optarg); |
| 239 | 237 | break; |
| | 238 | + case 'r': |
| | 239 | + /* only reply to every nth query, for high request rates */ |
| | 240 | + replynth=atoi(optarg); |
| | 241 | + break; |
| 240 | 242 | case 'n': |
| 241 | 243 | /* Predefined nice value */ |
| 242 | 244 | nice=atoi(optarg); |
| 243 | 245 | break; |
| 244 | 246 | default: |
| 245 | | - fprintf(stderr, "Usage: icpagent [-d] [-t delay time] [-p port] [-n nice] -m\n"); |
| | 247 | + fprintf(stderr, "Usage: icpagent [-d] [-t delay time] [-p port] [-n nice] [-r reply to every rth query] -m\n"); |
| 246 | 248 | exit(-1); |
| 247 | 249 | } |
| 248 | 250 | } |
| — | — | @@ -265,9 +267,9 @@ |
| 266 | 268 | |
| 267 | 269 | /* Static delays */ |
| 268 | 270 | t_int = (int)t; |
| 269 | | - frac = 10*(t - t_int + 0.0001); |
| | 271 | + frac = 100000*(t - t_int + 0.0000001); |
| 270 | 272 | if(frac > 0) |
| 271 | | - step = 10.0 / (float)frac; |
| | 273 | + step = 100000.0 / (float)frac; |
| 272 | 274 | // printf("frac: %d, step: %f\n",frac,step); |
| 273 | 275 | for (;;) { |
| 274 | 276 | bzero(&them, sizeof(them)); |
| — | — | @@ -302,23 +304,22 @@ |
| 303 | 305 | if (t<0) |
| 304 | 306 | queuereply(them,ICP_MISS, url, header.reqnum,0); |
| 305 | 307 | else { |
| 306 | | - if(tenloop == (int)stepsum || (tenloop == 9 ) && slow_c < frac) { |
| | 308 | + if(maincount == (int)stepsum || maincount == 999999 ) { |
| 307 | 309 | t_adjust = 1; |
| 308 | | - ++slow_c; |
| 309 | 310 | stepsum += step; |
| 310 | 311 | } else { |
| 311 | 312 | t_adjust = 0; |
| 312 | 313 | } |
| 313 | | - queuereply(them, opcode, url, header.reqnum, t_int+t_adjust); |
| | 314 | + |
| | 315 | + if(maincount % replynth == 0) |
| | 316 | + queuereply(them, opcode, url, header.reqnum, t_int+t_adjust); |
| 314 | 317 | } |
| 315 | 318 | |
| 316 | | - // printf("t %d, slow_c %d, ss %f\n",tenloop,slow_c,stepstack); |
| 317 | | - if(tenloop == 9) { |
| 318 | | - tenloop = 0; |
| 319 | | - slow_c = 0; |
| | 319 | + if(maincount == 999999) { |
| | 320 | + maincount = 0; |
| 320 | 321 | stepsum=0; |
| 321 | 322 | } else { |
| 322 | | - ++tenloop; |
| | 323 | + ++maincount; |
| 323 | 324 | } |
| 324 | 325 | } |
| 325 | 326 | } |
| Index: trunk/extensions/icpagent/README |
| — | — | @@ -11,6 +11,9 @@ |
| 12 | 12 | use negative number to send icp misses only |
| 13 | 13 | supports 0.1ms adjustments by varying the response times over ten |
| 14 | 14 | requests +/- 1ms to get the desired average. |
| | 15 | +-r - reply only to every nth query |
| | 16 | + Useful to dampen responses at very high request rates |
| | 17 | + set to something like 1/3 the total number of machines |
| 15 | 18 | |
| 16 | 19 | Example of remote management: |
| 17 | 20 | |