Commit graph

30 commits

Author SHA1 Message Date
Ankush Menat
a6c73dfdbe
fix: avoid flushing to monitor logs concurrently (#32552) 2025-05-16 12:20:40 +00:00
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
Ankush Menat
e85aa44843
fix: Remove misleading os.O_NONBLOCK flag (#28859)
This works likes this in C `open(2)` on file descriptor, not in python :)

In python it's setting buffering to enum value which in this case is
2048, if it were lower number this would've made performance worse.

ref:
- https://man7.org/linux/man-pages/man2/open.2.html#DESCRIPTION
- https://docs.python.org/3/library/functions.html#open
2024-12-23 05:22:13 +00:00
Gavin D'souza
c6580b5880
refactor: Replace pytz to std lib zoneinfo & datetime
Signed-off-by: Gavin D'souza <gavin.dsouza@switchup.de>
2024-12-06 15:43:33 +05:30
Ankush Menat
724d886f88
perf: Reduce 1 redis call while dumping monitor logs (#26337) 2024-05-06 12:53:36 +00:00
Ankush Menat
3c83b102ef fix: tz aware vs naive comparison 2023-11-24 15:03:08 +05:30
Ankush Menat
f526054ae2
refactor: Remove usage of utcnow (#23369) 2023-11-23 13:21:27 +05:30
Ankush Menat
11806c37a0 feat: error logs to include trace id 2023-08-23 14:20:24 +05:30
Ankush Menat
db90d4504e fix: let web servers set monitor trace id 2023-08-23 14:11:19 +05:30
Ankush Menat
59e49d89fe feat: include Trace ID in all SQL queries 2023-08-23 13:59:24 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Ankush Menat
a3a9e40aa4
fix: log requests even if no response (#20638) 2023-04-11 07:29:14 +05:30
Ankush Menat
939bf872ae fix: use compact JSON representation for monitor 2022-09-25 15:07:30 +05:30
Ankush Menat
967cc26fab feat: capture custom values in frappe monitor
lets monitor add extra info for:
- Save/Submit by doctype
- Report generation time by standard report name
2022-09-25 15:07:30 +05:30
Ankush Menat
1f9a6b010a
perf: add __slots__ to most used classes (#17421)
Added slots for these classes:

- Session - Created on EACH request
- LoginManager - Created on each request
- Monitor - Created on each request if monitor is enabled (usually in
  prod setup)
2022-07-07 11:15:50 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
2021-09-03 12:02:59 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
Aditya Hase
f71dc3c991 feat(rate-limiter): Log data with monitor 2020-05-13 12:34:07 +05:30
Sagar Vora
fb663291e8
fix: werkzeug.exceptions.BadRequestKeyError 2020-04-30 00:26:07 +05:30
Sagar Vora
a195421097
fix: do not check for frappe.conf.monitor while stopping monitor 2020-04-28 19:22:20 +05:30
Aditya Hase
4740e4f7e6 refactor: Monitor
Do not collect request headers
Collect job wait time and whether it was scheduled
2020-03-05 15:06:15 +05:30
Aditya Hase
268c577acd fix(monitor): Include request ip in monitored data 2020-03-05 15:06:15 +05:30
Aditya Hase
2b8c5a7f47 fix: Push a newline after all logs 2020-03-05 15:06:15 +05:30
Aditya Hase
cb3507f5e4 fix(monitor): Use datetime.utcnow() instead of timezone.utc
Python 2, 3 compatibility issue
2020-03-05 15:06:15 +05:30
Aditya Hase
56e1cdde53 fix(monitor): Add UUID to every log 2020-03-05 15:06:15 +05:30
Aditya Hase
ea3f5632d1 fix(monitor): Remove unused imports 2020-03-05 15:06:15 +05:30
Aditya Hase
96d9f2624b fix(monitor): Maintain MAX_LOG entries in cache 2020-03-05 15:06:15 +05:30
Aditya Hase
af3c4feb64 feat: Monitor
Collect HTTP Request and Background Job logs
2020-03-05 15:06:15 +05:30