#include <pagepool.h>
Inheritance diagram for ProxyTracePagePool:


Public Member Functions | |
| ProxyTracePagePool () | |
| virtual | ~ProxyTracePagePool () |
| virtual int | command (int argc, const char *const *argv) |
| int | num_pages () const |
| int | num_pages () const |
Protected Member Functions | |
| int | init_req (const char *fn) |
| int | init_page (const char *fn) |
| int | find_info () |
| ClientRequest * | load_req (int cid) |
| TclObject * | lookup_obj (const char *name) |
| TclObject * | lookup_obj (const char *name) |
Protected Attributes | |
| RandomVariable * | rvDyn_ |
| RandomVariable * | rvStatic_ |
| int | br_ |
| int * | size_ |
| FILE * | reqfile_ |
| Tcl_HashTable * | req_ |
| int | nclient_ |
| int | lastseq_ |
| int | num_pages_ |
| double | start_time_ |
| double | end_time_ |
| int | duration_ |
|
|
Definition at line 889 of file pagepool.cc.
|
|
|
Definition at line 895 of file pagepool.cc. References req_, reqfile_, and size_.
|
|
||||||||||||
|
Reimplemented from PagePool. Reimplemented in EPATracePagePool. Definition at line 1027 of file pagepool.cc. References br_, Scheduler::clock(), PagePool::command(), PagePool::duration_, init_page(), init_req(), Scheduler::instance(), load_req(), nclient_, ProxyTracePagePool::ClientRequest::nrt_, PagePool::num_pages_, ProxyTracePagePool::ClientRequest::nurl_, req_, rvDyn_, rvStatic_, size_, PagePool::start_time_, and RandomVariable::value(). Referenced by EPATracePagePool::command().
01028 {
01029 Tcl& tcl = Tcl::instance();
01030
01031 if (argc == 2) {
01032 if (strcmp(argv[1], "get-poolsize") == 0) {
01033 tcl.resultf("%u", num_pages_);
01034 return TCL_OK;
01035 } else if (strcmp(argv[1], "get-start-time") == 0) {
01036 tcl.resultf("%.17g", start_time_);
01037 return TCL_OK;
01038 } else if (strcmp(argv[1], "get-duration") == 0) {
01039 tcl.resultf("%d", duration_);
01040 return TCL_OK;
01041 } else if (strcmp(argv[1], "bimodal-ratio") == 0) {
01042 tcl.resultf("%g", br_ / 10);
01043 return TCL_OK;
01044 }
01045 } else if (argc == 3) {
01046 if (strcmp(argv[1], "set-client-num") == 0) {
01047 // Set the number of clients it'll access
01048 // Cannot be changed once set
01049 if (req_ != NULL)
01050 return TCL_ERROR;
01051 int num = atoi(argv[2]);
01052 req_ = new Tcl_HashTable;
01053 Tcl_InitHashTable(req_, TCL_ONE_WORD_KEYS);
01054 nclient_ = num;
01055 return TCL_OK;
01056 } else if (strcmp(argv[1], "gen-request") == 0) {
01057 // Use client id to get a corresponding request
01058 int id = atoi(argv[2]);
01059 ClientRequest *p = load_req(id);
01060 if ((p->nrt_ >= 0) &&
01061 (p->nrt_ < Scheduler::instance().clock())) {
01062 // XXX Do NOT treat this as an error, also
01063 // do NOT disable further requests from this
01064 // client.
01065 fprintf(stderr,
01066 "%.17g: Wrong request time %g.\n",
01067 Scheduler::instance().clock(),
01068 p->nrt_);
01069 // XXX If it's a little bit older than current
01070 // time, let it be a little bit later than now
01071 p->nrt_ = Scheduler::instance().clock()+0.001;
01072 }
01073 tcl.resultf("%lf %d",
01074 p->nrt_ - Scheduler::instance().clock(),
01075 p->nurl_);
01076 return TCL_OK;
01077 } else if (strcmp(argv[1], "gen-size") == 0) {
01078 int id = atoi(argv[2]);
01079 if ((id < 0) || (id > num_pages_)) {
01080 tcl.result("PagePool: id out of range.\n");
01081 return TCL_ERROR;
01082 }
01083 tcl.resultf("%d", size_[id]);
01084 return TCL_OK;
01085 } else if (strcmp(argv[1], "set-start-time") == 0) {
01086 start_time_ = strtod(argv[2], NULL);
01087 return TCL_OK;
01088 } else if (strcmp(argv[1], "bimodal-ratio") == 0) {
01089 // XXX Codes in Http/Server::gen-page{} also depends
01090 // on this dyn/static page algorithm. If this is
01091 // changed, that instproc must be changed too.
01092 //
01093 // percentage of dynamic pages. E.g.,
01094 // if this ratio is 5, then page 0-4 is
01095 // dynamic, and page 4-99 is static, and so on.
01096 double ratio = strtod(argv[2], NULL);
01097 //br_ = (int)ceil(ratio*100);
01098 br_ = (int)ceil(ratio*10);
01099 return TCL_OK;
01100 } else if (strcmp(argv[1], "ranvar-dp") == 0) {
01101 // Page mod ranvar for dynamic pages
01102 rvDyn_ = (RandomVariable*)TclObject::lookup(argv[2]);
01103 return TCL_OK;
01104 } else if (strcmp(argv[1], "ranvar-sp") == 0) {
01105 // page mod ranvar for static pages
01106 rvStatic_= (RandomVariable*)TclObject::lookup(argv[2]);
01107 return TCL_OK;
01108 } else if (strcmp(argv[1], "set-reqfile") == 0) {
01109 return init_req(argv[2]);
01110 } else if (strcmp(argv[1], "set-pagefile") == 0) {
01111 return init_page(argv[2]);
01112 } else if (strcmp(argv[1], "gen-init-modtime") == 0) {
01113 int id = atoi(argv[2]) % 10;
01114 if (id >= br_)
01115 // Static page
01116 tcl.result("0");
01117 else
01118 // Dynamic page
01119 tcl.resultf("%.17g",
01120 Scheduler::instance().clock());
01121 return TCL_OK;
01122 }
01123 } else {
01124 if (strcmp(argv[1], "gen-modtime") == 0) {
01125 if ((rvDyn_ == 0) || (rvStatic_ == 0)) {
01126 tcl.add_errorf("%s: no page age generator",
01127 name_);
01128 return TCL_ERROR;
01129 }
01130 // int id = atoi(argv[2]) % 100;
01131 int id = atoi(argv[2]) % 10;
01132 double mt = strtod(argv[3], NULL);
01133 if (id >= br_)
01134 tcl.resultf("%.17g", mt + rvStatic_->value());
01135 else
01136 tcl.resultf("%.17g", mt + rvDyn_->value());
01137 return TCL_OK;
01138 }
01139 }
01140
01141 return PagePool::command(argc, argv);
01142 }
|
Here is the call graph for this function:

|
|
Definition at line 922 of file pagepool.cc. References abort(), PagePool::duration_, len, PagePool::num_pages_, and reqfile_. Referenced by init_req().
00923 {
00924 // Read the last line of the file
00925 fseek(reqfile_, -128, SEEK_END);
00926 char buf[129];
00927 if (fread(buf, 1, 128, reqfile_) != 128) {
00928 fprintf(stderr,
00929 "ProxyTracePagePool: cannot read file information\n");
00930 return TCL_ERROR;
00931 }
00932 int i;
00933 // ignore the last RETURN
00934 buf[128] = 0;
00935 if (buf[127] == '\n')
00936 buf[127] = 0;
00937 for (i = 127; i >= 0; i--)
00938 if (buf[i] == '\n') {
00939 i++;
00940 break;
00941 }
00942 if (buf[i] != 'i') {
00943 fprintf(stderr,
00944 "ProxyTracePagePool: trace file doesn't contain statistics.\n");
00945 abort();
00946 }
00947 double len;
00948 sscanf(buf+i+1, "%lf %u", &len, &num_pages_);
00949 duration_ = (int)ceil(len);
00950 #if 0
00951 printf("ProxyTracePagePool: duration %d pages %u\n",
00952 duration_, num_pages_);
00953 #endif
00954 rewind(reqfile_);
00955 return TCL_OK;
00956 }
|
Here is the call graph for this function:

|
|
Definition at line 959 of file pagepool.cc. References PagePool::num_pages_, and size_. Referenced by command().
00960 {
00961 FILE *fp = fopen(fn, "r");
00962 if (fp == NULL) {
00963 fprintf(stderr,
00964 "ProxyTracePagePool: couldn't open trace file %s\n", fn);
00965 return TCL_ERROR;
00966 }
00967 if (size_ != NULL)
00968 delete []size_;
00969 int* p = new int[num_pages_];
00970 size_ = p;
00971 for (int i = 0; i < num_pages_; i++, p++)
00972 fscanf(fp, "%*d %*d %d %*u\n", p);
00973 fclose(fp);
00974 return TCL_OK;
00975 }
|
|
|
Definition at line 907 of file pagepool.cc. References find_info(), and reqfile_. Referenced by command().
00908 {
00909 reqfile_ = fopen(fn, "r");
00910 if (reqfile_ == NULL) {
00911 fprintf(stderr,
00912 "ProxyTracePagePool: couldn't open trace file %s\n", fn);
00913 return TCL_ERROR;
00914 }
00915
00916 // Discover information about the trace, e.g., number of pages,
00917 // start time, end time, etc. They should be available at the
00918 // first line of the trace file.
00919 return find_info();
00920 }
|
Here is the call graph for this function:

|
|
Definition at line 977 of file pagepool.cc. References ProxyTracePagePool::ClientRequest::fpos_, lastseq_, nclient_, ProxyTracePagePool::ClientRequest::nrt_, ProxyTracePagePool::ClientRequest::nurl_, req_, reqfile_, ProxyTracePagePool::ClientRequest::seq_, and PagePool::start_time_. Referenced by command().
00978 {
00979 // Find out which client we are seeking
00980 Tcl_HashEntry *he;
00981 ClientRequest *p;
00982 int dummy;
00983
00984 if ((he = Tcl_FindHashEntry(req_, (const char*)cid)) == NULL) {
00985 // New entry
00986 p = new ClientRequest();
00987 p->seq_ = lastseq_++;
00988 he = Tcl_CreateHashEntry(req_, (const char*)cid, &dummy);
00989 Tcl_SetHashValue(he, (const char*)p);
00990 // Search from the beginning of file for this new client
00991 fseek(reqfile_, 0, SEEK_SET);
00992 } else {
00993 p = (ClientRequest*)Tcl_GetHashValue(he);
00994 if (p->nrt_ == -1)
00995 // No more requests for this client
00996 return p;
00997 // Clear EOF status
00998 fseek(reqfile_, p->fpos_, SEEK_SET);
00999 }
01000
01001 // Looking for the next available request for this client
01002 double nrt;
01003 int ncid = -1, nurl;
01004 char buf[256];
01005 while (fgets(buf, 256, reqfile_)) {
01006 if (isalpha(buf[0])) {
01007 // Last line, break;
01008 ncid = -1;
01009 break;
01010 }
01011 sscanf(buf, "%lf %d %*d %d\n", &nrt, &ncid, &nurl);
01012 if ((ncid % nclient_) == p->seq_)
01013 break;
01014 }
01015 if ((ncid % nclient_) != p->seq_)
01016 // Didn't find the next request for this client
01017 p->nrt_ = -1;
01018 else {
01019 p->nrt_ = nrt, p->nurl_ = nurl;
01020 p->nrt_ += start_time_;
01021 }
01022 p->fpos_ = ftell(reqfile_);
01023 return p;
01024 }
|
|
|
Definition at line 242 of file pagepool.h.
00242 {
00243 TclObject* obj = Tcl::instance().lookup(name);
00244 if (obj == NULL)
00245 fprintf(stderr, "Bad object name %s\n", name);
00246 return obj;
00247 }
|
|
|
Definition at line 30 of file persconn.h. Referenced by WebTrafPool::command(), EmpWebTrafPool::command(), EmpFtpTrafPool::command(), WebTrafPool::lookup_rv(), EmpWebTrafPool::lookup_rv(), EmpFtpTrafPool::lookup_rv(), WebTrafPool::picksink(), EmpWebTrafPool::picksink(), EmpFtpTrafPool::picksink(), WebTrafPool::picktcp(), EmpWebTrafPool::picktcp(), and EmpFtpTrafPool::picktcp().
00030 {
00031 TclObject* obj = Tcl::instance().lookup(name);
00032 if (obj == NULL)
00033 fprintf(stderr, "Bad object name %s\n", name);
00034 return obj;
00035 }
|
|
|
Definition at line 233 of file pagepool.h. References PagePool::num_pages_.
00233 { return num_pages_; }
|
|
|
Definition at line 21 of file persconn.h. References PagePool::num_pages_.
00021 { return num_pages_; }
|
|
|
Definition at line 358 of file pagepool.h. Referenced by EPATracePagePool::command(), and command(). |
|
|
Definition at line 239 of file pagepool.h. Referenced by TracePagePool::change_time(), command(), CompMathPagePool::command(), MathPagePool::command(), TracePagePool::command(), MediaPagePool::command(), find_info(), and MediaPagePool::MediaPagePool(). |
|
|
Definition at line 238 of file pagepool.h. Referenced by TracePagePool::change_time(), CompMathPagePool::command(), MathPagePool::command(), TracePagePool::command(), MediaPagePool::command(), TracePagePool::load_page(), and PagePool::PagePool(). |
|
|
Definition at line 372 of file pagepool.h. Referenced by load_req(). |
|
|
Definition at line 372 of file pagepool.h. Referenced by command(), and load_req(). |
|
|
|
Definition at line 371 of file pagepool.h. Referenced by command(), load_req(), and ~ProxyTracePagePool(). |
|
|
Definition at line 360 of file pagepool.h. Referenced by find_info(), init_req(), load_req(), and ~ProxyTracePagePool(). |
|
|
Definition at line 357 of file pagepool.h. Referenced by EPATracePagePool::command(), and command(). |
|
|
Definition at line 357 of file pagepool.h. Referenced by command(). |
|
|
Definition at line 359 of file pagepool.h. Referenced by command(), init_page(), and ~ProxyTracePagePool(). |
|
|
Definition at line 237 of file pagepool.h. Referenced by TracePagePool::change_time(), command(), CompMathPagePool::command(), MathPagePool::command(), TracePagePool::command(), MediaPagePool::command(), TracePagePool::load_page(), load_req(), and PagePool::PagePool(). |
1.3.3