1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Where access-log lines go: a buffer per thread, written to stdout by a
//! background thread every [`FLUSH_INTERVAL`] (or at once when a buffer
//! passes [`SHARD_LIMIT`]), when the thread exits, and at process exit.
//! `println!` per request took the process-wide stdout lock and made one
//! `write` syscall per line — a sixth of a small request's CPU.
//!
//! Lines from one thread stay in order; lines from different threads are
//! interleaved by flush, each with its own timestamp. A line can reach
//! stdout up to [`FLUSH_INTERVAL`] after its request.
use Write;
use ;
use Duration;
/// How often the background thread writes out every buffer.
pub const FLUSH_INTERVAL: Duration = from_millis;
/// A thread's buffer is written out at once past this size.
pub const SHARD_LIMIT: usize = 32 * 1024;
;
/// This thread's shard; flushed and unregistered when the thread exits (the
/// blocking pool's threads come and go).
;
thread_local!
/// Append one line (written by `write`, without the newline) to this
/// thread's buffer.
pub
/// Write out every thread's buffered lines now.