|
41 | 41 | #include <arrow/table.h> |
42 | 42 | #include <arrow/util/key_value_metadata.h> |
43 | 43 |
|
44 | | -#include <thread> |
45 | | - |
46 | 44 | using namespace o2; |
47 | 45 | using namespace o2::aod; |
48 | 46 |
|
@@ -140,6 +138,8 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback() |
140 | 138 |
|
141 | 139 | auto filename = options.get<std::string>("aod-file-private"); |
142 | 140 |
|
| 141 | + auto maxRate = options.get<float>("aod-max-io-rate"); |
| 142 | + |
143 | 143 | std::string parentFileReplacement; |
144 | 144 | if (options.isSet("aod-parent-base-path-replacement")) { |
145 | 145 | parentFileReplacement = options.get<std::string>("aod-parent-base-path-replacement"); |
@@ -192,6 +192,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback() |
192 | 192 | fileCounter, |
193 | 193 | numTF, |
194 | 194 | watchdog, |
| 195 | + maxRate, |
195 | 196 | didir, reportTFN, reportTFFileName](Monitoring& monitoring, DataAllocator& outputs, ControlService& control, DeviceSpec const& device) { |
196 | 197 | // Each parallel reader device.inputTimesliceId reads the files fileCounter*device.maxInputTimeslices+device.inputTimesliceId |
197 | 198 | // the TF to read is numTF |
@@ -222,6 +223,8 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback() |
222 | 223 | return; |
223 | 224 | } |
224 | 225 |
|
| 226 | + int64_t startTime = uv_hrtime(); |
| 227 | + int64_t startSize = totalSizeCompressed; |
225 | 228 | for (auto& route : requestedTables) { |
226 | 229 | if ((device.inputTimesliceId % route.maxTimeslices) != route.timeslice) { |
227 | 230 | continue; |
@@ -278,6 +281,18 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback() |
278 | 281 | } |
279 | 282 | first = false; |
280 | 283 | } |
| 284 | + int64_t stopSize = totalSizeCompressed; |
| 285 | + int64_t bytesDelta = stopSize - startSize; |
| 286 | + int64_t stopTime = uv_hrtime(); |
| 287 | + float currentDelta = float(stopTime - startTime) / 1000000000; // in s |
| 288 | + if (ceil(maxRate) > 0.) { |
| 289 | + float extraTime = (bytesDelta / 1000000 - currentDelta * maxRate) / maxRate; |
| 290 | + // We only sleep if we read faster than the max-read-rate. |
| 291 | + if (extraTime > 0.) { |
| 292 | + LOGP(info, "Read {} MB in {} s. Sleeping for {} seconds to stay within {} MB/s limit.", bytesDelta / 1000000, currentDelta, extraTime, maxRate); |
| 293 | + uv_sleep(extraTime * 1000); // in milliseconds |
| 294 | + } |
| 295 | + } |
281 | 296 | totalDFSent++; |
282 | 297 | monitoring.send(Metric{(uint64_t)totalDFSent, "df-sent"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL)); |
283 | 298 | monitoring.send(Metric{(uint64_t)totalSizeUncompressed / 1000, "aod-bytes-read-uncompressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL)); |
|
0 commit comments