You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Improved ColoredFormatter to support microseconds in timestamps.
- Enhanced MultiProcessingLog to use a shared lock and prefix for log filenames.
- Updated ColoredLogger to handle new configuration options for log formatting and file handling.
- Added comprehensive tests for log filename configuration from various sources (environment variables, YAML, CLI).
- Refactored tests to remove unused imports and improve clarity.
- Ensured proper handling of log file creation and rotation settings.
- Added priority tests for log filename and date format configurations.
* The highest throughput was observed in the multiprocessing model, with nearly 27,000 messages processed per second.
20
+
* A good balance of throughput and resource utilization was achieved in the mixed mode (processes with threads).
21
+
* The multithreading model demonstrated consistent performance at around 10,000 messages per second.
22
+
* The standard logging library processed approximately 6,500 messages per second.
23
+
24
+
2.**Latency**:
25
+
* The lowest per-message latency (0.07-0.08ms) was provided by multiprocessing.
26
+
* Medium latency (0.17-0.21ms) was observed in mixed mode.
27
+
* Higher latency (0.26-0.42ms) was observed in thread-based approaches.
28
+
* Standard logging exhibited the highest latency (0.40-0.46ms) across all log levels.
29
+
30
+
3.**Resource Usage**:
31
+
* Minimal memory consumption (0.20-0.49MB) was observed across prismalog approaches.
32
+
* Standard logging showed the lowest memory increase (0.04MB) but with slower performance.
33
+
* Log file sizes remained compact (0.61-1.13MB) across all approaches.
34
+
35
+
4.**Timestamp Formatting Impact**:
36
+
***Crucially, the choice of timestamp format significantly impacts performance.** Using `%(created)f` (which logs a raw numeric timestamp) can achieve substantially higher throughput (observed up to **~35,000 msgs/sec** in testing) compared to using `%(asctime)s` (which formats the timestamp into a human-readable string, observed maxing out around **~25,000 msgs/sec**).
37
+
* While `%(created)f` requires post-processing to convert timestamps for readability, it drastically reduces logging overhead.
15
38
16
39
### Results Summary
17
40
@@ -41,26 +64,59 @@ Comprehensive benchmarks were conducted to evaluate the performance characterist
41
64
- Standard logging showed the lowest memory increase (0.04MB) but with slower performance.
42
65
- Log file sizes remained compact (0.61-1.13MB) across all approaches.
43
66
67
+
### Performance Benchmarking
68
+
69
+
The `benchmark/performance_test.py` script allows you to measure logging performance under different concurrency models.
70
+
71
+
**Arguments:**
72
+
73
+
*`-p N`, `--processes N`: Use N worker processes (default: 2).
74
+
*`-t M`, `--threads M`: Use M worker threads per process (default: 2).
75
+
76
+
**Examples:**
77
+
78
+
***Multiprocessing Test (e.g., 3 processes, 1 thread each):**
79
+
```bash
80
+
python benchmark/performance_test.py -p 3 -t 1
81
+
```
82
+
83
+
***Multithreading Test (e.g., 1 process, 3 threads):**
84
+
```bash
85
+
python benchmark/performance_test.py -p 1 -t 3
86
+
```
87
+
88
+
***Mixed Concurrency Test (e.g., 2 processes, 2 threads each):**
89
+
```bash
90
+
python benchmark/performance_test.py -p 2 -t 2
91
+
# Or simply run with defaults:
92
+
# python benchmark/performance_test.py
93
+
```
94
+
95
+
The script also accepts standard `prismalog` arguments like `--log-level`, `--log-format`, etc., to configure the logger during the benchmark. Rotation is automatically disabled during the benchmark run for consistent results.
96
+
44
97
### Feature Advantages Over Standard Logging
45
98
46
99
While performance benchmarks provide valuable insights, several important features are offered by `prismalog` that are not available in the standard logging library:
47
100
48
-
1.**Color-coded Console Output**:
101
+
1. **Process-Safe & Thread-Safe File Handling**:
102
+
* The included file handlers (`MultiProcessingLog`) are specifically designed to handle concurrent writes from multiple processes and threads safely, preventing log corruption or race conditions. Standard `RotatingFileHandler` is not inherently process-safe without external locking mechanisms.
103
+
104
+
2. **Color-coded Console Output**:
49
105
- Syntax highlighting for log messages is applied automatically based on their severity level.
50
106
- Customizable color schemes are supported for different environments.
51
107
- Readability is improved by visually distinguishing between different message types.
52
108
53
-
2.**Special Critical Message Handling**:
109
+
3. **Special Critical Message Handling**:
54
110
- Application termination on critical errors is optionally supported.
55
111
- Configurable callbacks for critical message events are provided.
56
112
- Stack trace preservation is ensured for critical failures.
57
113
58
-
3.**Advanced Configuration**:
114
+
4. **Advanced Configuration**:
59
115
- Environment variable support is included, with sensible defaults and multiple fallback patterns.
60
116
- Command-line argument integration is supported, with automatic help generation.
61
117
- Configuration file support (YAML) is provided, with automatic detection.
62
118
63
-
4.**Developer Experience Enhancements**:
119
+
5. **Developer Experience Enhancements**:
64
120
- A simplified API is offered for common logging patterns.
65
121
- Context managers are provided for temporary logging level changes.
66
122
- Convenient decorators are included forfunctionentry/exit logging.
0 commit comments