okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-eng: GitHub engine items for 0.2.76ca60e9a0

main
22.8 KiB495 linesraw
1// src/ngram/ple_reader_stress_test.cpp - #3602: the direct table reader under load, every delivered row compared byte
2// for byte with a plain buffered read of the same file.  CPU and a temp file only, no model, no GPU.
3//
4//   ple_reader_stress_test [--dir D] [--seconds S] [--big] [--no-sparse-check]
5//
6// What it covers that ple_reader_test --selftest does not:
7//   * several client threads issuing and collecting at once (the io thread, the row cache and the slot buffers are
8//     shared), several tickets outstanding per client, collected in any order;
9//   * a row cache so small that nearly every insert evicts, next to one that holds everything;
10//   * max_inflight 1 and 2 (a slot is reused at once), randomly injected completion delays, the keep-alive reads;
11//   * rows that straddle a page boundary at every phase (header offsets 0, 192, 4051, 4000 and row sizes 90, 110, 160,
12//     4096), the first and last rows of the table, a file with and without bytes after the table, out-of-range rows;
13//   * "late writers": every collected buffer is kept and compared again after later tickets ran, so a read that
14//     lands in a buffer after `collect` returned shows up;
15//   * the reader after a failed read: the next issue/collect must fail, not wait for ever (Linux: the file is cut
16//     short under the open reader);
17//   * --big: a sparse table whose rows sit at file offsets around 2^31 and 2^32 and at the end of a 5 GiB file.
18#include "strata/ngram/ple_reader.hpp"
19#include "strata/platform/direct_file.hpp"
20
21#include <algorithm>
22#include <atomic>
23#include <chrono>
24#include <cstdint>
25#include <cstdio>
26#include <cstdlib>
27#include <cstring>
28#include <deque>
29#include <filesystem>
30#include <fstream>
31#include <future>
32#include <mutex>
33#include <random>
34#include <set>
35#include <string>
36#include <thread>
37#include <vector>
38
39#if defined(_WIN32)
40#define WIN32_LEAN_AND_MEAN
41#define NOMINMAX
42#include <windows.h>
43#include <winioctl.h>
44#else
45#include <unistd.h>
46#endif
47
48namespace ng = strata::ngram;
49
50namespace {
51
52std::atomic<int> g_fail{0};
53std::mutex g_print;
54#define CHECK(c, ...)                                                                          \
55    do {                                                                                       \
56        if (!(c)) {                                                                            \
57            std::lock_guard<std::mutex> lk_(g_print);                                          \
58            std::fprintf(stderr, "FAIL %s:%d: ", __FILE__, __LINE__);                          \
59            std::fprintf(stderr, __VA_ARGS__);                                                 \
60            std::fprintf(stderr, "\n");                                                        \
61            ++g_fail;                                                                          \
62        }                                                                                      \
63    } while (0)
64
65constexpr uint32_t PAGE = ng::PAGE;
66
67/// The bytes of row `row` (rb bytes): a xorshift stream seeded by the row, so no two rows alike and a row read from
68/// the wrong place never looks like another row's.
69void fill_row(uint32_t row, uint32_t rb, uint8_t* out) {
70    uint64_t x = 0x9E3779B97F4A7C15ull * (uint64_t) (row + 1) + 0x1234567ull;
71    for (uint32_t b = 0; b < rb; ++b) {
72        x ^= x << 13;
73        x ^= x >> 7;
74        x ^= x << 17;
75        out[b] = (uint8_t) (x >> 24);
76    }
77}
78
79struct Spec {
80    const char* name;
81    uint32_t rb;
82    uint64_t header;
83    uint32_t n_rows;
84    uint64_t trailing;   // bytes after the table
85};
86
87bool make_table(const std::string& path, const Spec& s) {
88    std::ofstream f(path, std::ios::binary | std::ios::trunc);
89    if (!f) return false;
90    std::vector<uint8_t> head(s.header, 0xAB);
91    if (!head.empty()) f.write((const char*) head.data(), (std::streamsize) head.size());
92    std::vector<uint8_t> r(s.rb);
93    for (uint32_t i = 0; i < s.n_rows; ++i) {
94        fill_row(i, s.rb, r.data());
95        f.write((const char*) r.data(), s.rb);
96    }
97    std::vector<uint8_t> tail(s.trailing, 0xEE);
98    if (!tail.empty()) f.write((const char*) tail.data(), (std::streamsize) tail.size());
99    return (bool) f;
100}
101
102/// A buffered read of the file: the reference.
103struct Ref {
104    std::ifstream f;
105    uint64_t header;
106    uint32_t rb;
107    uint64_t n_rows;
108    Ref(const std::string& path, uint64_t h, uint32_t r, uint64_t n) : f(path, std::ios::binary), header(h), rb(r), n_rows(n) {}
109    void row(uint32_t r, uint8_t* out) {
110        if (r >= n_rows) {
111            std::memset(out, 0, rb);
112            return;
113        }
114        f.clear();
115        f.seekg((std::streamoff) (header + (uint64_t) r * rb));
116        f.read((char*) out, rb);
117        if ((uint32_t) f.gcount() != rb) std::memset(out, 0x77, rb);   // the reference itself failed: never equal
118    }
119};
120
121struct Delivered {
122    std::vector<uint32_t> rows;
123    std::vector<uint8_t> buf;
124};
125
126/// 0 = delivered bytes equal the reference (and, where `expect` is set, the generated row).
127bool verify(Ref& ref, const Delivered& d, uint32_t rb, const char* what, bool generated) {
128    std::vector<uint8_t> want(rb), gen(rb);
129    for (size_t i = 0; i < d.rows.size(); ++i) {
130        ref.row(d.rows[i], want.data());
131        if (std::memcmp(want.data(), &d.buf[i * rb], rb) != 0) {
132            size_t b = 0;
133            while (b < rb && want[b] == d.buf[i * rb + b]) ++b;
134            CHECK(false, "%s: row %u (index %zu of %zu) differs from the file at byte %zu", what, d.rows[i], i, d.rows.size(), b);
135            return false;
136        }
137        if (generated && d.rows[i] < ref.n_rows) {
138            fill_row(d.rows[i], rb, gen.data());
139            if (std::memcmp(gen.data(), want.data(), rb) != 0) {
140                CHECK(false, "%s: row %u: the file is not what the writer wrote", what, d.rows[i]);
141                return false;
142            }
143        }
144    }
145    return true;
146}
147
148struct Picker {
149    const Spec& s;
150    std::vector<uint32_t> straddlers, tail_rows, hot;
151    explicit Picker(const Spec& sp, std::mt19937& rng) : s(sp) {
152        for (uint32_t r = 0; r < s.n_rows; ++r) {
153            const uint64_t a = s.header + (uint64_t) r * s.rb;
154            if (a / PAGE != (a + s.rb - 1) / PAGE) straddlers.push_back(r);
155        }
156        for (uint32_t k = 0; k < 200 && k < s.n_rows; ++k) tail_rows.push_back(s.n_rows - 1 - k);
157        for (int k = 0; k < 48; ++k) hot.push_back(rng() % s.n_rows);
158    }
159    uint32_t one(std::mt19937& rng) const {
160        switch (rng() % 9) {
161            case 0: return straddlers.empty() ? rng() % s.n_rows : straddlers[rng() % straddlers.size()];
162            case 1: return tail_rows[rng() % tail_rows.size()];
163            case 2: return hot[rng() % hot.size()];
164            case 3: return (uint32_t) (rng() % 3) + (uint32_t) (rng() % 4);                 // the first rows
165            case 4: return s.n_rows + (uint32_t) (rng() % 4);                                 // just out of range
166            case 5: return rng() % 40 == 0 ? 0xFFFFFFFFu : rng() % s.n_rows;
167            default: return rng() % s.n_rows;
168        }
169    }
170    std::vector<uint32_t> make(std::mt19937& rng) const {
171        static const size_t sizes[] = {1, 2, 5, 16, 16, 17, 64, 130, 700, 2500};
172        const size_t n = sizes[rng() % (sizeof sizes / sizeof sizes[0])];
173        std::vector<uint32_t> r;
174        r.reserve(n);
175        switch (rng() % 5) {
176            case 0: {   // a run: neighbours share pages
177                const uint32_t at = rng() % s.n_rows;
178                for (size_t i = 0; i < n; ++i) r.push_back(at + (uint32_t) i);
179                break;
180            }
181            case 1:     // duplicates
182                for (size_t i = 0; i < n; ++i) r.push_back(hot[rng() % 4]);
183                break;
184            default:
185                for (size_t i = 0; i < n; ++i) r.push_back(one(rng));
186        }
187        return r;
188    }
189};
190
191struct Config {
192    bool threaded;
193    uint32_t inflight;
194    uint64_t cache_rows;
195    bool delay;
196    bool keepalive;
197    int clients;
198};
199
200void client(ng::PleReader& rd, const Spec& s, const Picker& pk, const std::string& path, uint32_t seed,
201            std::chrono::steady_clock::time_point until, long min_tickets, std::atomic<long>& done) {
202    std::mt19937 rng(seed);
203    Ref ref(path, s.header, s.rb, s.n_rows);
204    std::deque<Delivered> keep;
205    long tickets = 0;
206    while (std::chrono::steady_clock::now() < until || tickets < min_tickets) {
207        const int k = 1 + (int) (rng() % 3);
208        std::vector<Delivered> ds((size_t) k);
209        std::vector<ng::PleReader::Ticket> ts((size_t) k);
210        for (int j = 0; j < k; ++j) {
211            ds[(size_t) j].rows = pk.make(rng);
212            ds[(size_t) j].buf.assign(ds[(size_t) j].rows.size() * s.rb, 0xCC);
213            ts[(size_t) j] = rd.issue(ds[(size_t) j].rows.data(), ds[(size_t) j].rows.size(), ds[(size_t) j].buf.data());
214        }
215        std::vector<int> order((size_t) k);
216        for (int j = 0; j < k; ++j) order[(size_t) j] = j;
217        std::shuffle(order.begin(), order.end(), rng);
218        for (int j : order) {
219            std::string err;
220            if (!rd.collect(ts[(size_t) j], err)) {
221                CHECK(false, "collect failed: %s", err.c_str());
222                return;
223            }
224            verify(ref, ds[(size_t) j], s.rb, "ticket", true);
225            ++tickets;
226            keep.push_back(std::move(ds[(size_t) j]));
227            if (keep.size() > 6) keep.pop_front();
228        }
229        if (rng() % 4 == 0)   // late writers: what was collected earlier must still be what it was
230            for (const Delivered& d : keep) verify(ref, d, s.rb, "buffer changed after collect", false);
231        if (g_fail.load() > 20) return;
232    }
233    for (const Delivered& d : keep) verify(ref, d, s.rb, "buffer changed after collect (end)", false);
234    done += tickets;
235}
236
237bool run_config(const std::string& dir, const Spec& s, const Config& c, double seconds, uint32_t seed) {
238    const std::string path = dir + "/ple_stress_" + std::to_string(s.rb) + "_" + std::to_string(s.header) + ".bin";
239    std::mt19937 rng(seed);
240    Picker pk(s, rng);
241    ng::PleReader rd;
242    std::string err;
243    const uint64_t cache_rows = std::min<uint64_t>(c.cache_rows, (64ull << 20) / s.rb);   // at most 64 MiB of cache
244    if (!rd.open(path, s.header, s.n_rows, c.inflight, cache_rows, err, c.threaded, s.rb)) {
245        std::fprintf(stderr, "cannot open %s: %s\n", path.c_str(), err.c_str());
246        return false;
247    }
248    if (c.keepalive) rd.set_keepalive(1.0, 2.0);
249    std::atomic<bool> stop{false};
250    std::thread chaos;
251    // (the caller-thread reader has no lock: its delay is set once, from this thread, before any client starts)
252    if (c.delay && !c.threaded) rd.set_injected_delay_us(300);
253    if (c.delay && c.threaded)
254        chaos = std::thread([&] {
255            std::mt19937 r(seed ^ 77u);
256            while (!stop.load()) {
257                static const double d[] = {0, 0, 150, 600, 2500};
258                rd.set_injected_delay_us(d[r() % 5]);
259                std::this_thread::sleep_for(std::chrono::milliseconds(3));
260            }
261            rd.set_injected_delay_us(0);
262        });
263    const auto until = std::chrono::steady_clock::now() + std::chrono::milliseconds((long) (seconds * 1000));
264    std::atomic<long> done{0};
265    std::vector<std::thread> th;
266    const int clients = c.threaded ? c.clients : 1;
267    // a run that is slow (delays) still makes at least this many tickets per client
268    for (int i = 0; i < clients; ++i)
269        th.emplace_back(client, std::ref(rd), std::cref(s), std::cref(pk), std::cref(path), seed + 1000u * (uint32_t) i, until, 12L,
270                        std::ref(done));
271    for (auto& t : th) t.join();
272    stop = true;
273    if (chaos.joinable()) chaos.join();
274    CHECK(rd.cache_size() <= rd.cache_capacity(), "row cache %llu over its capacity %llu", (unsigned long long) rd.cache_size(),
275          (unsigned long long) rd.cache_capacity());
276    const ng::ReaderStats st = rd.snapshot();
277    std::printf("  %-14s rb %3u hdr %4llu | %s inflight %2u cache %5llu%s%s clients %d: %ld tickets, %llu rows, %.1f%% cache hits, %llu reads\n",
278                s.name, s.rb, (unsigned long long) s.header, c.threaded ? "thread" : "caller", c.inflight,
279                (unsigned long long) c.cache_rows, c.delay ? " delay" : "", c.keepalive ? " keepalive" : "", clients,
280                done.load(), (unsigned long long) st.requests, st.requests ? 100.0 * (double) st.cache_hits / (double) st.requests : 0.0,
281                (unsigned long long) st.reads);
282    rd.close();
283    return true;
284}
285
286#if !defined(_WIN32)
287/// After a failed read the reader must keep failing (collect returns false) and must not hang.
288void error_does_not_hang(const std::string& dir) {
289    const Spec s{"error", 90, 192, 20000, 0};
290    const std::string path = dir + "/ple_stress_error.bin";
291    if (!make_table(path, s)) { CHECK(false, "cannot write %s", path.c_str()); return; }
292    for (bool threaded : {true, false}) {
293        if (!make_table(path, s)) { CHECK(false, "cannot rewrite %s", path.c_str()); return; }
294        ng::PleReader rd;
295        std::string err;
296        if (!rd.open(path, s.header, s.n_rows, 8, 0, err, threaded, s.rb)) { CHECK(false, "open: %s", err.c_str()); return; }
297        std::vector<uint32_t> rows = {0, 1, 2, 3};
298        std::vector<uint8_t> out(rows.size() * s.rb);
299        CHECK(rd.collect(rd.issue(rows.data(), rows.size(), out.data()), err), "first ticket: %s", err.c_str());
300        // cut the file short under the open reader: every page past the cut now reads as a short read
301        if (truncate(path.c_str(), (off_t) (s.header + 100 * s.rb)) != 0) { CHECK(false, "truncate failed"); return; }
302        std::vector<uint32_t> beyond = {15000, 15001, 19999};
303        std::vector<uint8_t> out2(beyond.size() * s.rb);
304        auto go = std::async(std::launch::async, [&]() -> int {
305            std::string e1, e2, e3;
306            const bool a = rd.collect(rd.issue(beyond.data(), beyond.size(), out2.data()), e1);
307            // a ticket after the failure: nothing to read (or something the cache holds) - it must still return
308            std::vector<uint32_t> again = {5, 15500};
309            std::vector<uint8_t> out3(again.size() * s.rb);
310            const bool b = rd.collect(rd.issue(again.data(), again.size(), out3.data()), e2);
311            const bool c = rd.collect(rd.issue(beyond.data(), beyond.size(), out2.data()), e3);
312            return (a ? 1 : 0) | (b ? 2 : 0) | (c ? 4 : 0);
313        });
314        if (go.wait_for(std::chrono::seconds(20)) != std::future_status::ready) {
315            std::fprintf(stderr, "FAIL: a ticket issued after a failed read never returned (%s reader)\n", threaded ? "thread" : "caller");
316            ++g_fail;
317            std::_Exit(3);   // the reader's destructor would wait for the same thing
318        }
319        const int r = go.get();
320        CHECK((r & 1) == 0, "a read past the cut file did not fail (%s reader)", threaded ? "thread" : "caller");
321        CHECK((r & 2) == 0 && (r & 4) == 0, "a ticket after the failure succeeded (mask %d, %s reader)", r, threaded ? "thread" : "caller");
322        rd.close();
323    }
324    std::filesystem::remove(path);
325    std::printf("  error path: a failed read fails the next tickets too, none hangs\n");
326}
327#endif
328
329// ----------------------------------------------------------------------------------------------- the big sparse table
330/// A sparse file of `size` bytes with the given (offset, bytes) pieces written.
331bool make_sparse(const std::string& path, uint64_t size, const std::vector<std::pair<uint64_t, std::vector<uint8_t>>>& pieces) {
332#if defined(_WIN32)
333    HANDLE h = CreateFileA(path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
334    if (h == INVALID_HANDLE_VALUE) return false;
335    DWORD ret = 0;
336    DeviceIoControl(h, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, &ret, nullptr);   // if it is refused the file is just big
337    bool ok = true;
338    for (const auto& p : pieces) {
339        LARGE_INTEGER at;
340        at.QuadPart = (LONGLONG) p.first;
341        DWORD w = 0;
342        ok = ok && SetFilePointerEx(h, at, nullptr, FILE_BEGIN) && WriteFile(h, p.second.data(), (DWORD) p.second.size(), &w, nullptr) &&
343             w == p.second.size();
344    }
345    LARGE_INTEGER end;
346    end.QuadPart = (LONGLONG) size;
347    ok = ok && SetFilePointerEx(h, end, nullptr, FILE_BEGIN) && SetEndOfFile(h);
348    CloseHandle(h);
349    return ok;
350#else
351    {
352        std::ofstream f(path, std::ios::binary | std::ios::trunc);
353        if (!f) return false;
354        for (const auto& p : pieces) {
355            f.seekp((std::streamoff) p.first);
356            f.write((const char*) p.second.data(), (std::streamsize) p.second.size());
357        }
358        if (!f) return false;
359    }
360    std::error_code ec;
361    std::filesystem::resize_file(path, size, ec);
362    return !ec;
363#endif
364}
365
366void big_offsets(const std::string& dir) {
367    constexpr uint32_t RB = 90;
368    constexpr uint64_t HEADER = 192;
369    constexpr uint32_t N = 61000000u;                       // 5.49e9 bytes: past 2^32 (4.29e9), below 2^33
370    const uint64_t size = HEADER + (uint64_t) N * RB;
371    std::set<uint32_t> marks;
372    auto around = [&](uint64_t byte_offset) {
373        const uint32_t r = (uint32_t) ((byte_offset - HEADER) / RB);
374        for (int d = -3; d <= 3; ++d)
375            if ((int64_t) r + d >= 0 && (uint64_t) ((int64_t) r + d) < N) marks.insert((uint32_t) ((int64_t) r + d));
376    };
377    around(1ull << 31);
378    around((1ull << 32) - 4096);
379    around(1ull << 32);
380    around((1ull << 32) + 4096);
381    around(3ull << 30);
382    around(5ull << 30);
383    for (uint32_t k = 0; k < 6; ++k) marks.insert(N - 1 - k);
384    for (uint32_t k = 0; k < 4; ++k) marks.insert(k);
385    // rows that cross a page boundary in the neighbourhood of 2^32
386    for (uint32_t r = (uint32_t) (((1ull << 32) - HEADER) / RB) - 200; r < (uint32_t) (((1ull << 32) - HEADER) / RB) + 200; ++r) {
387        const uint64_t a = HEADER + (uint64_t) r * RB;
388        if (a / PAGE != (a + RB - 1) / PAGE) marks.insert(r);
389    }
390    std::vector<std::pair<uint64_t, std::vector<uint8_t>>> pieces;
391    for (uint32_t r : marks) {
392        std::vector<uint8_t> b(RB);
393        fill_row(r, RB, b.data());
394        pieces.emplace_back(HEADER + (uint64_t) r * RB, std::move(b));
395    }
396    const std::string path = dir + "/ple_stress_big.bin";
397    if (!make_sparse(path, size, pieces)) {
398        std::fprintf(stderr, "  big table: cannot create the sparse file here, skipped\n");
399        return;
400    }
401    Ref ref(path, HEADER, RB, N);
402    std::mt19937 rng(99);
403    for (bool threaded : {true, false}) {
404        ng::PleReader rd;
405        std::string err;
406        if (!rd.open(path, HEADER, N, 16, 1024, err, threaded, RB)) { CHECK(false, "big open: %s", err.c_str()); break; }
407        std::vector<uint32_t> mk(marks.begin(), marks.end());
408        for (int round = 0; round < 40; ++round) {
409            Delivered d;
410            for (int i = 0; i < 64; ++i) d.rows.push_back(rng() % 3 == 0 ? (uint32_t) (rng() % N) : mk[rng() % mk.size()]);
411            d.buf.assign(d.rows.size() * RB, 0xCC);
412            CHECK(rd.collect(rd.issue(d.rows.data(), d.rows.size(), d.buf.data()), err), "big collect: %s", err.c_str());
413            verify(ref, d, RB, "big table", false);
414            // and against what was written: a marked row is its generated bytes, any other row is zeros
415            std::vector<uint8_t> want(RB);
416            for (size_t i = 0; i < d.rows.size(); ++i) {
417                if (marks.count(d.rows[i])) fill_row(d.rows[i], RB, want.data());
418                else std::memset(want.data(), 0, RB);
419                CHECK(std::memcmp(want.data(), &d.buf[i * RB], RB) == 0, "big table: row %u is not what was written", d.rows[i]);
420            }
421        }
422        rd.close();
423    }
424    std::error_code ec;
425    std::filesystem::remove(path, ec);
426    std::printf("  big table: %zu marked rows at offsets around 2^31, 2^32 and the end of a %.2f GiB file, both readers: done\n",
427                marks.size(), (double) size / (1024.0 * 1024.0 * 1024.0));
428}
429
430}  // namespace
431
432int main(int argc, char** argv) {
433    std::string dir = std::filesystem::temp_directory_path().string();
434    double seconds = 0.3;
435    bool big = false, only_error = false;
436    for (int i = 1; i < argc; ++i) {
437        const std::string a = argv[i];
438        if (a == "--dir" && i + 1 < argc) dir = argv[++i];
439        else if (a == "--seconds" && i + 1 < argc) seconds = std::atof(argv[++i]);
440        else if (a == "--big") big = true;
441        else if (a == "--only-error-path") only_error = true;
442        else { std::fprintf(stderr, "usage: ple_reader_stress_test [--dir D] [--seconds S] [--big] [--only-error-path]\n"); return 2; }
443    }
444    // a file system without direct reads (tmpfs on an older kernel): say so and skip
445    {
446        const std::string probe = dir + "/ple_stress_probe.bin";
447        const Spec s{"probe", 90, 192, 1000, 0};
448        if (!make_table(probe, s)) { std::fprintf(stderr, "cannot write in %s\n", dir.c_str()); return 2; }
449        ng::PleReader rd;
450        std::string err;
451        const bool ok = rd.open(probe, s.header, s.n_rows, 4, 0, err, true, s.rb);
452        rd.close();
453        std::filesystem::remove(probe);
454        if (!ok) {
455            std::printf("SKIP: direct reads are not possible in %s (%s)\n", dir.c_str(), err.c_str());
456            return 77;
457        }
458    }
459    const Spec specs[] = {
460        {"iq4nl", 90, 192, 150000, 0},          // the real shard's shape: header 192, 90-byte rows, the table ends the file
461        {"iq4nl+tail", 90, 192, 150000, 777},   // bytes after the table
462        {"odd phase", 90, 4051, 120000, 0},     // the first row straddles
463        {"q5_0", 110, 4000, 100000, 0},
464        {"fp8", 160, 0, 90000, 123},
465        {"page row", 4096, 192, 3000, 0},       // every row crosses a page boundary
466        {"tiny", 1, 5, 30000, 0},
467    };
468    std::vector<Config> cfgs;
469    for (uint32_t inflight : {1u, 2u, 3u, 64u})
470        for (uint64_t cache : {0ull, 16ull, 100000ull})
471            cfgs.push_back({true, inflight, cache, (inflight + cache) % 2 == 0, inflight == 2, 4});
472    cfgs.push_back({false, 1, 16, false, false, 1});
473    cfgs.push_back({false, 8, 100000, false, false, 1});
474    cfgs.push_back({false, 64, 0, true, false, 1});
475    std::printf("ple_reader stress: %zu tables x %zu configurations, %.1f s each (dir %s)\n", sizeof specs / sizeof specs[0],
476                cfgs.size(), seconds, dir.c_str());
477    uint32_t seed = 1;
478    for (const Spec& s : specs) {
479        if (only_error) break;
480        const std::string path = dir + "/ple_stress_" + std::to_string(s.rb) + "_" + std::to_string(s.header) + ".bin";
481        if (!make_table(path, s)) { std::fprintf(stderr, "cannot write %s\n", path.c_str()); return 2; }
482        for (const Config& c : cfgs) {
483            if (!run_config(dir, s, c, seconds, ++seed)) return 2;
484            if (g_fail.load() > 0) break;
485        }
486        std::filesystem::remove(path);
487        if (g_fail.load() > 0) break;
488    }
489#if !defined(_WIN32)
490    if (g_fail.load() == 0) error_does_not_hang(dir);
491#endif
492    if (big && g_fail.load() == 0) big_offsets(dir);
493    std::printf("ple_reader stress: %s\n", g_fail.load() ? "FAILED" : "OK");
494    return g_fail.load() ? 1 : 0;
495}