Skip to content

Read tiles into an unzeroed buffer from the request pool, save ~0.6ms per tile - #517

Merged
hummeltech merged 4 commits into
openstreetmap:masterfrom
leijurv:buf-alloc-perf
Oct 15, 2026
Merged

hummeltech merged 4 commits into
openstreetmap:masterfrom
leijurv:buf-alloc-perf

Conversation

@leijurv

@leijurv leijurv commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Ever since #491, #492, tile_handler_serve's 1 megabyte buffer has been zero filled and pulled from a fresh pool with its own allocator, destroyed after every request. This means every tile request is going to fault in and zero 256 fresh pages of memory. This contends significantly under multithreaded load on the mmap lock. I have a test setup that mirrors tile.osm.org as well as I can (full planet, replaying tile requests, event MPM, 64 threads per child, HTTPS enabled, 28% of requests are If-None-Match conditional). Apache's CPU time per tile is decreased from 755 micros to 134 micro with this PR, which allocates the buffer from the request pool without zeroing it out. This matches the behavior of v0.8.1 which used plain malloc. The 134 micro time now matches v0.8.1 again.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.05%. Comparing base (c4e3e62) to head (d0120af).
⚠️ Report is 45 commits behind head on master.

Files with missing lines Patch % Lines
src/mod_tile.c 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #517      +/-   ##
==========================================
+ Coverage   81.54%   82.05%   +0.51%     
==========================================
  Files          24       24              
  Lines        5645     5321     -324     
==========================================
- Hits         4603     4366     -237     
+ Misses       1042      955      -87     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leijurv

leijurv commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

This one is actually not ready, as we can see from mac osx CI....

@leijurv
leijurv marked this pull request as draft October 15, 2026 20:30
@leijurv

leijurv commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Okay so actually the mac failure is due to a build time vs runtime discrepancy in apache portable runtime. mod_tile was built against APR 1.5.2, but the tests used homebrew's httpd 2.4.68 which linked against APR 1.7.6. This creates a strange situation where mod_tile's calls to apr_* are assuming 1.5.2 but the request pool objects were made by APR 1.7.6 from httpd. The allocator struct changed between those versions and a bunch of fields have different offsets which causes an immediate segfault on the first tile. Interestingly, smaller allocations are succeeding purely by chance because they only touch fields that didn't move.

@leijurv
leijurv marked this pull request as ready for review October 15, 2026 20:39
@leijurv

leijurv commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

I was going to try to split this out into two or three stacked PRs but that would be confusing so I'll just update it here. We can fix the issue better by having APR's symbols bind to httpd's version at load time like how httpd's own symbols do already.

@hummeltech
hummeltech merged commit f19e453 into openstreetmap:master Oct 15, 2026
38 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants