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
Copy file name to clipboardExpand all lines: multiple-servers/IMPLEMENTATION.md
+175-1Lines changed: 175 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ Copied over from server-database, with file split up:
51
51
52
52
This has the same setup steps as server-database, so those can be copied over.
53
53
54
-
# Ports
54
+
##Ports
55
55
56
56
`cmd` files should allow ports to be configred using `--port`.
57
57
@@ -64,3 +64,177 @@ Switch static server over to 8082.
64
64
```
65
65
nginx -c `pwd`/config/nginx.conf
66
66
```
67
+
68
+
## Benchmark
69
+
70
+
`ab` the API:
71
+
72
+
```console
73
+
> ab -n 5000 -c 25 "http://127.0.0.1:8080/api/images.json"
74
+
This is ApacheBench, Version 2.3 <$Revision: 1901567 $>
75
+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
76
+
Licensed to The Apache Software Foundation, http://www.apache.org/
77
+
78
+
Benchmarking 127.0.0.1 (be patient)
79
+
80
+
Completed 500 requests
81
+
Completed 1000 requests
82
+
Completed 1500 requests
83
+
Completed 2000 requests
84
+
Completed 2500 requests
85
+
Completed 3000 requests
86
+
Completed 3500 requests
87
+
Completed 4000 requests
88
+
Completed 4500 requests
89
+
Completed 5000 requests
90
+
Finished 5000 requests
91
+
92
+
93
+
Server Software: nginx/1.23.1
94
+
Server Hostname: 127.0.0.1
95
+
Server Port: 8080
96
+
97
+
Document Path: /api/images.json
98
+
Document Length: 4 bytes
99
+
100
+
Concurrency Level: 25
101
+
Time taken for tests: 1.866 seconds
102
+
Complete requests: 5000
103
+
Failed requests: 0
104
+
Total transferred: 885000 bytes
105
+
HTML transferred: 20000 bytes
106
+
Requests per second: 2680.08 [#/sec] (mean)
107
+
Time per request: 9.328 [ms] (mean)
108
+
Time per request: 0.373 [ms] (mean, across all concurrent requests)
109
+
Transfer rate: 463.26 [Kbytes/sec] received
110
+
111
+
Connection Times (ms)
112
+
min mean[+/-sd] median max
113
+
Connect: 0 1 2.0 1 59
114
+
Processing: 1 8 24.2 3 322
115
+
Waiting: 0 7 20.3 3 322
116
+
Total: 1 9 24.3 4 323
117
+
118
+
Percentage of the requests served within a certain time (ms)
119
+
50% 4
120
+
66% 4
121
+
75% 5
122
+
80% 6
123
+
90% 28
124
+
95% 34
125
+
98% 37
126
+
99% 62
127
+
100% 323 (longest request)
128
+
```
129
+
130
+
And the static server:
131
+
132
+
```console
133
+
> ab -n 5000 -c 25 "http://127.0.0.1:8080/"
134
+
This is ApacheBench, Version 2.3 <$Revision: 1901567 $>
135
+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
136
+
Licensed to The Apache Software Foundation, http://www.apache.org/
137
+
138
+
Benchmarking 127.0.0.1 (be patient)
139
+
Completed 500 requests
140
+
Completed 1000 requests
141
+
Completed 1500 requests
142
+
Completed 2000 requests
143
+
Completed 2500 requests
144
+
Completed 3000 requests
145
+
Completed 3500 requests
146
+
Completed 4000 requests
147
+
Completed 4500 requests
148
+
Completed 5000 requests
149
+
Finished 5000 requests
150
+
151
+
152
+
Server Software: nginx/1.23.1
153
+
Server Hostname: 127.0.0.1
154
+
Server Port: 8080
155
+
156
+
Document Path: /
157
+
Document Length: 607 bytes
158
+
159
+
Concurrency Level: 25
160
+
Time taken for tests: 1.502 seconds
161
+
Complete requests: 5000
162
+
Failed requests: 0
163
+
Total transferred: 4165000 bytes
164
+
HTML transferred: 3035000 bytes
165
+
Requests per second: 3328.26 [#/sec] (mean)
166
+
Time per request: 7.511 [ms] (mean)
167
+
Time per request: 0.300 [ms] (mean, across all concurrent requests)
168
+
Transfer rate: 2707.46 [Kbytes/sec] received
169
+
170
+
Connection Times (ms)
171
+
min mean[+/-sd] median max
172
+
Connect: 0 1 0.3 1 3
173
+
Processing: 1 7 10.2 3 115
174
+
Waiting: 1 6 9.2 3 115
175
+
Total: 2 7 10.1 4 116
176
+
177
+
Percentage of the requests served within a certain time (ms)
178
+
50% 4
179
+
66% 4
180
+
75% 5
181
+
80% 9
182
+
90% 23
183
+
95% 25
184
+
98% 27
185
+
99% 28
186
+
100% 116 (longest request)
187
+
```
188
+
189
+
## Multiple backends
190
+
191
+
```nginx
192
+
http {
193
+
...
194
+
195
+
# Define a group of API servers that nginx can use
196
+
upstream api {
197
+
server localhost:8081;
198
+
}
199
+
200
+
...
201
+
202
+
proxy_pass http://api/;
203
+
204
+
...
205
+
}
206
+
```
207
+
208
+
Add alternatives:
209
+
210
+
```nginx
211
+
server localhost:8083;
212
+
server localhost:8084;
213
+
```
214
+
215
+
Run them:
216
+
217
+
```console
218
+
> DATABASE_URL='postgres://localhost:5432/go-server-database' go run ./cmd/api-server --port 8083
219
+
> DATABASE_URL='postgres://localhost:5432/go-server-database' go run ./cmd/api-server --port 8084
220
+
```
221
+
222
+
Run a small `ab` (`ab -n 10 -c 10 "http://127.0.0.1:8080/api/images.json"`) and observe the server logs: the requests are distributed between the servers.
223
+
224
+
Turn off one of the servers and run another small `ab`: `ab -n 10 -c 10 "http://127.0.0.1:8080/api/images.json"`
0 commit comments