seitime-frappe/frappe/model
Ankush Menat 9b79dfeb7b
perf: "random" naming to improve concurrency and locality (#30053)
This feels overengineered and it kinda is, but other efforts to
inroduce sequential naming/UUID naming haven't been that fruitful
either.

10 character random "hash" i now changed to.

1. first character - last character in UUID4 ID of request/job
2. three characters - derived from current timestamp.
4. 6 characters - random data.

This satisfies all three requirements:

1. Readers - temporal locality should result in spatial locality on disk. (fewer pages accessed)
2. Single writer - temporal locality should result in spatial locality. (fewer dirty pages)
3. Multiple writers - temporal locality should NOT result in spatial locality. (less lock contention)

Mostly concludes https://github.com/frappe/frappe/pull/25309 and https://github.com/frappe/frappe/pull/28349

Rough probabiliy numbers

Assumptions:
- Unique per worker prefix - 16 (uuid's base16 version)
- Rough time spent generating names - 10% of request (very very conservative estimate)

Probability(collision) = P(at least one prefix collision) * P(time collision)
Probability(collision) = (1 - p(all different)) * 10%
Probability(collision) = (1 - (16! / 16-N! )/ 16^N ) * 10%

| N (concurrency) | Probability(collision) |
| 1  |    0.0% |
| 2  |    0.6% |
| 3  |    1.8% |
| 4  |    3.3% |
| 5  |    5.0% |
| 6  |    6.6% |
| 7  |    7.9% |
| 8  |    8.8% |
2025-01-25 07:04:09 +00:00
..
utils refactor: fixup with ruff 0.8.1 2024-12-04 13:18:04 +05:30
__init__.py refactor: fixup with ruff 0.8.1 2024-12-04 13:18:04 +05:30
base_document.py fix: don't override setstate (#29194) 2025-01-16 15:50:47 +05:30
create_new.py style: re-format with ruff 2024-02-05 18:53:33 +05:30
db_query.py perf: misc client cache improvements (#29070) 2025-01-07 16:14:43 +05:30
delete_doc.py refactor: use doc.check_permission (#28317) 2024-11-22 10:41:24 +01:00
docfield.py chore!: dead code (#19551) 2023-01-10 18:53:08 +05:30
docstatus.py feat: utility methods for docstatus (#15515) 2022-02-04 07:41:25 +00:00
document.py perf: misc client cache improvements (#29070) 2025-01-07 16:14:43 +05:30
dynamic_links.py perf: cache dynamic links map in Redis (#28878) 2024-12-23 19:43:05 +05:30
mapper.py Revert "fix: don't skip perm check when Apply Strict User Permissions is enabled (#29916)" 2025-01-24 19:56:44 +01:00
meta.py refactor: Use @cached_property (#29212) 2025-01-17 06:09:05 +00:00
naming.py perf: "random" naming to improve concurrency and locality (#30053) 2025-01-25 07:04:09 +00:00
rename_doc.py perf: Skip link checking on internal deletes 2025-01-06 11:48:19 +05:30
sync.py refactor: fixup with ruff 0.8.1 2024-12-04 13:18:04 +05:30
trace.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
virtual_doctype.py refactor: migrate virtual doctypes to new API 2024-03-11 18:25:05 +05:30
workflow.py fix: workflow should also support queue_in_background 2024-12-03 07:02:27 +00:00