MCPcopy Create free account
hub / github.com/apache/trafficserver / isAttemptReq

Function isAttemptReq

plugins/esi/test/sampleProb.cc:119–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119bool
120isAttemptReq(string URL, FailureData &data)
121{
122 FailureData::iterator it;
123 it = data.find(URL);
124 if (it != data.end()) {
125 double avg = 0;
126 vector<pair<double, double>> &passFail = it->second->_passFail;
127
128 for (int i = 0; i < it->second->_totalSlot; i++) {
129 // cout<<"Failure:"<<passFail[i].first<< "Total"<< (passFail[i].first+passFail[i].second )<<endl;
130 if (passFail[i].first > 0) {
131 avg += passFail[i].first / (passFail[i].first + passFail[i].second);
132 // cout<<"Prob of failure:"<<passFail[i].first/(passFail[i].first+passFail[i].second)<<endl;
133 }
134 }
135
136 if (avg) {
137 avg = avg / it->second->_totalSlot;
138 double prob;
139
140 if (avg * 1000 < lowerCutOff) {
141 prob = avg;
142 }
143
144 else {
145 double mapFactor = (((avg * 1000 - lowerCutOff) * (avg * 1000 - lowerCutOff)) / (higherCutOff - lowerCutOff)) + lowerCutOff;
146 prob = mapFactor / 1000;
147 cout << prob << endl;
148 }
149
150 if (prob == 1) {
151 prob = it->second->_avgOverWindow;
152 cout << "Average" << prob << endl;
153 }
154
155 int decision = rand() % 100;
156
157 if (decision < prob * 100)
158 return false;
159
160 return true;
161 }
162 return true;
163
164 } else {
165 FailureInfo *info = new FailureInfo();
166 data[URL] = info;
167 return true;
168 }
169}
170
171const std::string fetchURL = "www.example.com";
172int

Callers 1

mainFunction · 0.85

Calls 2

findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected