yonchicy opened a new issue, #71064: URL: https://github.com/apache/doris/issues/71064
### Search before asking - [ ] I had searched in the [issues](https://github.com/apache/doris/issues) and found no similar issues. Related, but not duplicates: - #69916 reports that a constant LIKE/REGEXP pattern is recompiled for every clone (per scanner and per segment). That inefficiency is the trigger here. - #65428 reports a startup deadlock caused by the same `dlsym(RTLD_NEXT, "dl_iterate_phdr")` call inside the interposer. This issue reports the *query latency* consequence: once the interposer is active, every exception unwind pays a `dlsym` and an extra global loader lock. I could not find an issue covering the interaction of the two, which is what makes a single query ~4x slower after an upgrade that only enables the interposer. ### Version - Doris 4.1.3 based build, Cloud (storage-compute decoupled) mode, 3 FE + 10 BE. - glibc 2.28, 256 cores and 48 scanner threads per BE (`doris_scanner_thread_pool_thread_num = 48`). - A/B between two builds of the same internal branch: - before: `0c0c2f4f6c349e395483a87dcea0a76f1f48f322`, where the `dl_iterate_phdr` interposer is commented out; - after: `f8009023b17be522795846d49a0b97345e45fe54`, which contains the #64093 backport and enables the interposer. - Source inspection of `be/src/common/phdr_cache.cpp` on master (modified 2026-09-20) shows the same uncached `dlsym` on the forwarding path. ### What's wrong? A dashboard query that contains a constant `REGEXP` predicate became 4.1x-4.3x slower after an upgrade whose only relevant BE change was enabling the process-wide `dl_iterate_phdr` interposer. Scan rows are identical and scanned bytes are slightly lower, so this is not a data or IO change. Same SQL, same partitions, literal execution, identical session variables: | build | query_time | cpu_time_ms | scan_rows | scan_bytes | |---|---:|---:|---:|---:| | before | 15,454 ms | 6,532,289 | 4,663,577,922 | 768 GB | | after (run 1) | 66,899 ms | 25,717,023 | 4,669,413,292 | 716 GB | | after (run 2, warm cache) | 63,141 ms | 26,243,704 | 4,669,413,292 | 714 GB | Profile, summed over the 160 `OLAP_SCAN` instances of the query: | counter | before | after | ratio | |---|---:|---:|---:| | `SegmentIteratorInitTimer` | 5,683,000 ms | 25,360,000 ms | 4.46x | | `ScannerGetBlockTime` | 6,827,000 ms | 25,620,000 ms | 3.75x | | `BlockFetchTime` | 1,358,000 ms | 2,273,000 ms | 1.67x | | named init sub-timers (`SegmentLoadIndexTimer`, `SegmentCreateColumnReadersTimer`, ...) | - | flat or faster | - | Per segment, iterator initialization goes from about 4.0 ms to 18.9 ms, while the number of segments decreases slightly (about 9,077 to 8,501). The aggregate/union/exchange operators stay in the millisecond range. On-CPU profiles of the query (150 s window per BE) show `hs_compile` under `SegmentIterator::_construct_compound_expr_context`, and `_Unwind_Find_FDE -> dlsym` stacks on all three sampled BEs. Scanner threads spend roughly 48%-50% of their samples in futex and 46%-48% in kernel spin, up from about 12%-15% before. ### What you expected to happen? Enabling the stack-trace support should not change the cost of ordinary unwinding. A query whose plan, scan volume and session variables are unchanged should keep its latency. ### How to reproduce? The full query needs a large table, but the forwarding cost can be isolated in a small program: 1. Link the third-party Hyperscan used by Doris (5.4.2) and compile the same constant pattern in a loop from N threads: `^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?$` with `HS_FLAG_DOTALL | HS_FLAG_ALLOWEMPTY | HS_FLAG_UTF8` and `HS_MODE_BLOCK`. 2. Build `be/src/common/phdr_cache.cpp` from master into the same binary (`-rdynamic -ldl`). The ordinary `dl_iterate_phdr` interposer is enough; `USE_UNWIND` is not needed for this path. 3. Run 100 compiles per thread with 1, 32 and 48 threads. 4. Change `void* func = dlsym(RTLD_NEXT, "dl_iterate_phdr");` to `static void* func = ...` and rerun. Median of three interleaved runs on one host: | threads | no interposer | master interposer | interposer + cached pointer | |---:|---:|---:|---:| | 1 | 0.238 s | 0.245 s | 0.237 s | | 32 | 1.201 s | 1.834 s | 1.212 s | | 48 | 1.803 s | **3.007 s** | **1.832 s** | Process system CPU at 48 threads: 65.4 s -> 113.1 s -> 66.5 s. Single-threaded runs are unchanged, which points at lock contention rather than extra work in the compiler. Counting with `-Wl,--wrap=dlsym` and `-Wl,--wrap=__cxa_throw`: one compile raises 42 C++ exceptions and performs 410 `dlsym` calls; 100 compiles perform 41,000. With the pointer cached, 100 compiles still raise 4,200 exceptions but perform 1 `dlsym`. This is a microbenchmark, not the full BE, so the absolute numbers are not the production ratio. The direction and the scaling with thread count are the point. ### Anything else? **Why this query.** `FunctionRegexpLike::open` builds the Hyperscan database in the `THREAD_LOCAL` open. `VExprContext::clone` opens `THREAD_LOCAL` again, and `SegmentIterator::_construct_compound_expr_context` clones the pushed-down expression once per segment, so a constant pattern is compiled once per segment. Hyperscan's `removeCyclicPathRedundancy` uses `throw/catch` as control flow, so each compile raises a few dozen exceptions. **What changed.** Each of those exceptions unwinds through `_Unwind_Find_FDE` and calls `dl_iterate_phdr`. Before #64093 the process-wide symbol was glibc's implementation. After #64093 the interposer forwards through `getOriginalDLIteratePHDR()`, which performs `dlsym(RTLD_NEXT, "dl_iterate_phdr")` on every call and does not cache the result. glibc's `dlsym` takes `dl_load_lock`, and the original `dl_iterate_phdr` then takes `dl_load_write_lock`, so every unwind now pays an extra symbol lookup (which allocates) plus an extra global lock acquisition. With 48 scanner threads per BE this serializes. Queries on the same table without a constant REGEXP predicate do not degrade, because they never enter the per-segment `hs_compile` path. **Fix directions.** 1. Cache the resolved original `dl_iterate_phdr` pointer and forward through it, so the ordinary path costs one indirect call. Resolving it once during startup (for example from `updatePHDRCache()`, before worker threads start) also removes the re-entrancy hazard described in #65428. 2. Implement #69916: compile the constant pattern once per fragment, share the read-only database, and give each state its own scratch via `hs_clone_scratch`. A per-BE LRU cache would additionally amortize repeated scheduled queries. The two are complementary: (1) protects every unwind user, including jemalloc and other regexes; (2) removes the repeated compile that makes this query sensitive to it. Note that #68217 already excludes the interposer under ASAN because of the same `dlsym` re-entry. Non-ASAN builds still take the slow path. **Limitations.** The production A/B is on an internal branch, so the exact commit SHAs are not in apache/doris. The standalone reproducer above uses master's `phdr_cache.cpp` and the same Hyperscan version, and is the part that can be reproduced upstream without the internal data. - [ ] Yes I am willing to submit a PR! - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/doris/blob/master/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
