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
Uncomment and set the SECRET_KEY to the output of the python command above.
110
+
**Remember to keep this key secret, and do not push it to git/github.** You may change it, even when the system is in use, but note that users may be logged out.
111
+
See here for more info: https://medium.com/@bayraktar.eralp/changing-rotating-django-secret-key-without-logging-users-out-804a29d3ea65
112
+
113
+
Disable debug mode by setting `debug = False`.
114
+
For security reasons this should always be off on a production server, only turn it on if you need to actually debug.
115
+
116
+
Add your domain to ALLOWED_HOST, for example like so:
If you are not using HTTPS, you are essentially transferring everything, login password, images, on the webpage totally unencrypted over the internet!
156
+
To use HTTPS/SSL encryption you need an SSL certificate, you can buy one cheap from services like [namecheap.com](https://www.namecheap.com) or free from [Let's encrypt](https://letsencrypt.org/).
157
+
Store the certificate, the key, and the CA certificate files on the server, e.g. in folder /var/www/learn-pathology/ssl/.
158
+
The config with SSL/HTTPS end-to-end-encryption will then look something like this:
Open your browser and check that the webpage works.
208
+
A usual cause of error on the apache2 server, when enabling the website, is a syntax error in the configuration file. In such situations, you can use the command line `apache2ctl configtest` to debug the file.
209
+
210
+
**12. Server Optimizations**
211
+
212
+
**Use mpm_worker to enable multi-processing and multi-threading**
213
+
214
+
By default, apache will use mpm_prefork to handle multiple requests, which do not use any multi-threading.
215
+
If you plan to serve hundreds of simultaneous users, you should consider using mpm_worker instead.
216
+
217
+
To do so, first enable mpm_worker:
218
+
```bash
219
+
sudo a2dismod mpm_prefork
220
+
sudo a2enmod mpm_worker
221
+
sudo service apache2 restart
222
+
```
223
+
Then open the mpm_worker config: `sudo nano /etc/apache2/mods-enabled/mpm_worker.conf`
224
+
225
+
The following config has worked well for us:
226
+
```
227
+
<IfModule mpm_worker_module>
228
+
ServerLimit 32
229
+
StartServers 16
230
+
MinSpareThreads 50
231
+
MaxSpareThreads 100
232
+
ThreadLimit 64
233
+
ThreadsPerChild 50
234
+
MaxRequestWorkers 512
235
+
MaxConnectionsPerChild 0
236
+
</IfModule>
237
+
```
238
+
Restart apache after changes:
239
+
```bash
240
+
sudo service apache2 restart
241
+
```
242
+
243
+
**Enable turbojpeg**
244
+
245
+
Requested image tiles have to be compressed with JPEG before they are sent to the users.
246
+
By default, PIL is used for compression which is slow. Turbo JPEG is a faster option.
247
+
248
+
To use TurboJPEG, first install it:
249
+
```bash
250
+
sudo apt install libturbojpeg
251
+
```
252
+
and install it in your python environment:
253
+
```bash
254
+
pip install PyTurboJPEG==1.7.*
255
+
```
256
+
then enable it in learnpathology/settings.py:
257
+
```python
258
+
USE_TURBOJPEG=True
259
+
```
260
+
261
+
Reload apache after changes:
262
+
```bash
263
+
sudo service apache2 reload
264
+
```
265
+
266
+
**Cache tiles in memory using memcached**
267
+
268
+
In an educational setting, you might have several hundred students which will
269
+
access the same few images at the same time during class.
270
+
Since reading images from the harddrive is one of the slowest operations, you
271
+
can considerably improve performance by having the images in memory instead.
272
+
In this case, all students, except the first one, accessing an image, will read
273
+
images directly from memory instead of the slow harddrive.
274
+
275
+
We recommend using memcached for this purpose, you can install it like this:
276
+
```bash
277
+
sudo apt update
278
+
sudo apt install memcached libmemcached-tools
279
+
sudo service memcached start
280
+
```
281
+
282
+
Modify memcached config to allow it to use a lot of memory and large enough objects to be stored:
283
+
`nano /etc/memcached.conf`:
284
+
```
285
+
# Depending how much RAM you have, set the limit of you much
286
+
# memory memcached should be allowed to use, here we have set it
287
+
# to 100 GB = 100*1024 = 102400 MB:
288
+
-m 102400
289
+
# Allow file sizes up to 3 MB
290
+
-I 3m
291
+
```
292
+
293
+
Restart after modifying the config:
294
+
```bash
295
+
sudo service memcached restart
296
+
```
297
+
298
+
Install the pymemcache binding in your python environment:
299
+
```bash
300
+
pip install pymemcache==4.*
301
+
```
302
+
303
+
Enable the tile caching in learnpathology/settings.py:
304
+
```python
305
+
USE_TILE_CACHE=True
306
+
```
307
+
308
+
Reload apache after modifying settings:
309
+
```bash
310
+
sudo service apache2 reload
311
+
```
312
+
313
+
You can check if memcached is working by looking at its statistics (how many items are stored, number of cache hits/misses etc.):
314
+
```bash
315
+
memcstat --servers="127.0.0.1"
316
+
```
317
+
318
+
The images are stored for 30 minutes in memory as defined in slide/views.py:
319
+
```python
320
+
@cache_page(60*30)
321
+
deftile(request, slide_id, osd_level, x, y):
322
+
...
323
+
```
324
+
325
+
Learn Pathology is set to store a maximum of 100 000 images, here are the settings we have used (defined in learnpathology/settings.py):
0 commit comments