70 auto& selected = offers[
ref];
71 auto& info = infos[
ref];
73 if (info.firstUsed == 0) {
82 stats.invalidOffers.clear();
83 stats.otherUser.clear();
84 stats.unexpiring.clear();
85 stats.selectedOffers.clear();
86 stats.expired.clear();
96 O2_SIGNPOST_START(quota, sid,
"summary",
"%zu offers were selected for a total of: cpu %d, memory %lli, shared memory %lli",
97 result.size(), totalOffer.cpu, totalOffer.memory, totalOffer.sharedMemory);
98 for (
auto& offer :
result) {
105 O2_SIGNPOST_START(quota, sid,
"summary",
"Not enough resources to select offers.");
111 if (stats.invalidOffers.size()) {
112 O2_SIGNPOST_EVENT_EMIT(quota, sid,
"summary",
"The following offers were invalid: %s", fmt::format(
"{}", fmt::join(stats.invalidOffers,
", ")).c_str());
114 if (stats.otherUser.size()) {
115 O2_SIGNPOST_EVENT_EMIT(quota, sid,
"summary",
"The following offers were owned by other users: %s", fmt::format(
"{}", fmt::join(stats.otherUser,
", ")).c_str());
117 if (stats.expired.size()) {
118 O2_SIGNPOST_EVENT_EMIT(quota, sid,
"summary",
"The following offers are expired: %s", fmt::format(
"{}", fmt::join(stats.expired,
", ")).c_str());
120 if (stats.unexpiring.size() > 1) {
121 O2_SIGNPOST_EVENT_EMIT(quota, sid,
"summary",
"The following offers will never expire: %s", fmt::format(
"{}", fmt::join(stats.unexpiring,
", ")).c_str());
129 int64_t minValidity = 0;
142 if (offer.valid ==
false) {
144 stats.invalidOffers.push_back(
i);
147 if (offer.user != -1 && offer.user != task) {
149 stats.otherUser.push_back(
i);
152 if (offer.runtime < 0) {
153 stats.unexpiring.push_back(
i);
154 }
else if (offer.runtime + info.received < now) {
155 O2_SIGNPOST_EVENT_EMIT(quota, qid,
"select",
"Offer %d expired since %llu milliseconds and holds %llu MB and %llu timeslices",
156 i, now - offer.runtime - info.received, offer.sharedMemory / 1000000, offer.timeslices);
158 stats.expired.push_back(
i);
161 O2_SIGNPOST_EVENT_EMIT(quota, qid,
"select",
"Offer %d still valid for %llu milliseconds, providing %llu MB and %llu timeslices",
162 i, offer.runtime + info.received - now, offer.sharedMemory / 1000000, offer.timeslices);
163 if (minValidity == 0) {
164 minValidity = offer.runtime + info.received - now;
166 minValidity = std::min(minValidity, (int64_t)(offer.runtime + info.received - now));
169 assert(offer.sharedMemory >= 0);
170 auto tmp = accumulated;
171 tmp.
cpu += offer.cpu;
172 tmp.memory += offer.memory;
173 tmp.sharedMemory += offer.sharedMemory;
174 tmp.timeslices += offer.timeslices;
175 offer.score = selector(offer, accumulated);
176 switch (offer.score) {
186 stats.selectedOffers.push_back(
i);
187 O2_SIGNPOST_EVENT_EMIT(quota, qid,
"select",
"Offer %d selected but not enough. %llu MB, %d cores and %llu timeslices are not enough.",
188 i, tmp.sharedMemory / 1000000, tmp.cpu, tmp.timeslices);
193 stats.selectedOffers.push_back(
i);
195 O2_SIGNPOST_EVENT_EMIT(quota, qid,
"select",
"Selected %zu offers providing %llu MB, %d cores and %llu timeslices are deemed enough.",
196 stats.selectedOffers.size(), tmp.sharedMemory / 1000000, tmp.cpu, tmp.timeslices);
201 if (minValidity != 0) {
205 O2_SIGNPOST_EVENT_EMIT(quota, tid,
"select",
"Offer should be expired by now, checking again."); }, minValidity + 100, 0);
208 return summarizeWhatHappended(enough, stats.selectedOffers, accumulated, stats);
#define O2_DECLARE_DYNAMIC_LOG(name)
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer)
#define O2_SIGNPOST_END(log, id, name, format,...)
#define O2_SIGNPOST_ID_GENERATE(name, log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
#define O2_SIGNPOST_END_WITH_ERROR(log, id, name, format,...)
#define O2_SIGNPOST_START(log, id, name, format,...)
std::function< void(int id, std::array< ComputingQuotaOffer, 16 > &, ComputingQuotaStats &, std::function< void(ComputingQuotaOffer const &, ComputingQuotaStats &stats)>)> ComputingQuotaConsumer