1
2 /* Web Polygraph http://www.web-polygraph.org/
3 * Copyright 2003-2011 The Measurement Factory
4 * Licensed under the Apache License, Version 2.0 */
5
6 #include "pgl/pgl.h"
7
8 #include "xstd/String.h"
9 #include "xstd/gadgets.h"
10 #include "pgl/PglRec.h"
11 #include "pgl/PglRateSym.h"
12 #include "pgl/BenchSideSym.h"
13 #include "pgl/BenchSym.h"
14
15
16
17 String BenchSym::TheType = "Bench";
18
19 static String strClient_side = "client_side";
20 static String strProxy_side = "proxy_side";
21 static String strServer_side = "server_side";
22 static String strPeak_req_rate = "peak_req_rate";
23
24
BenchSym()25 BenchSym::BenchSym(): RecSym(TheType, new PglRec) {
26 theRec->bAdd(RateSym::TheType, strPeak_req_rate, 0);
27 theRec->bAdd(BenchSideSym::TheType, strClient_side, new BenchSideSym);
28 theRec->bAdd(BenchSideSym::TheType, strServer_side, new BenchSideSym);
29 theRec->bAdd(BenchSideSym::TheType, strProxy_side, new BenchSideSym);
30 }
31
BenchSym(const String & aType,PglRec * aRec)32 BenchSym::BenchSym(const String &aType, PglRec *aRec): RecSym(aType, aRec) {
33 }
34
isA(const String & type) const35 bool BenchSym::isA(const String &type) const {
36 return RecSym::isA(type) || type == TheType;
37 }
38
dupe(const String & type) const39 SynSym *BenchSym::dupe(const String &type) const {
40 if (isA(type))
41 return new BenchSym(this->type(), theRec->clone());
42 return RecSym::dupe(type);
43 }
44
peakReqRate(double & rate) const45 bool BenchSym::peakReqRate(double &rate) const {
46 return getRate(strPeak_req_rate, rate);
47 }
48
clientSide() const49 const BenchSideSym *BenchSym::clientSide() const {
50 return getSide(strClient_side);
51 }
52
serverSide() const53 const BenchSideSym *BenchSym::serverSide() const {
54 return getSide(strServer_side);
55 }
56
proxySide() const57 const BenchSideSym *BenchSym::proxySide() const {
58 return getSide(strProxy_side);
59 }
60
side(const String & name) const61 const BenchSideSym *BenchSym::side(const String &name) const {
62 return getSide(name + "_side");
63 }
64
clientHostCount(int & count) const65 String BenchSym::clientHostCount(int &count) const {
66 const BenchSideSym *side = clientSide();
67 if (!side)
68 return "client side of the bench is not configured";
69
70 double peakRate;
71 if (!peakReqRate(peakRate))
72 return "peak_req_rate is not set for the bench";
73 if (peakRate <= 0)
74 return "peak_req_rate is not positive for the bench";
75
76 double hostLoad;
77 if (!side->maxHostLoad(hostLoad))
78 return "max_host_load is not set for the client side of the bench";
79 if (hostLoad <= 0)
80 return "max_host_load is not positive for the client side of the bench";
81
82 count = (int)xceil(peakRate, hostLoad);
83 return String();
84 }
85
getSide(const String & name) const86 const BenchSideSym *BenchSym::getSide(const String &name) const {
87 SynSymTblItem *si = 0;
88 Assert(theRec);
89 Assert(theRec->find(name, si));
90 if (!si->sym())
91 return 0;
92
93 const BenchSideSym *side = &(const BenchSideSym&)si->sym()->cast(BenchSideSym::TheType);
94 side->bench(this);
95 return side;
96 }
97