Commit Graph

13 Commits

Author SHA1 Message Date
Pea Tyczynska
e6e363ba3f Add antivirus scan to letter validation preview view 2018-10-05 16:27:57 +01:00
Athanasios Voutsadakis
b56addb4ff Remove GUNICORN_CMD_ARGS before we start our app
Cloudfoundry adds this env var which forces gunicorn to print
its access log to stdout because reasons.

This also takes precedence over *anything* we put in our config file,
including disabling the access logs.

Related commit:
7b350f292a (diff-153f90501612878d9c6fcd50247547bcR526)
2018-06-25 16:39:18 +01:00
Leo Hemsted
cc3b2f1ab9 disable gunicorn access logs
they're turning up in syslog, which means they're getting into kibana now

also move config settings from manifest to gunicorn_config.py
2018-06-25 11:24:31 +01:00
Athanasios Voutsadakis
f1eecd4e18 Enable syslog drain on all environments 2018-06-21 11:48:48 +01:00
Leo Hemsted
d675ceb5c2 send zendesk rather than deskpro tickets 2018-04-24 17:37:15 +01:00
Chris Hill-Scott
24dbe7b7b1 Add Redis cache between admin and API
Most of the time spent by the admin app to generate a page is spent
waiting for the API. This is slow for three reasons:

1. Talking to the API means going out to the internet, then through
   nginx, the Flask app, SQLAlchemy, down to the database, and then
   serialising the result to JSON and making it into a HTTP response
2. Each call to the API is synchronous, therefore if a page needs 3 API
   calls to render then the second API call won’t be made until the
   first has finished, and the third won’t start until the second has
   finished
3. Every request for a service page in the admin app makes a minimum
   of two requests to the API (`GET /service/…` and `GET /user/…`)

Hitting the database will always be the slowest part of an app like
Notify. But this slowness is exacerbated by 2. and 3. Conversely every
speedup made to 1. is multiplied by 2. and 3.

So this pull request aims to make 1. a _lot_ faster by taking nginx,
Flask, SQLAlchemy and the database out of the equation. It replaces them
with Redis, which as an in-memory key/value store is a lot faster than
Postgres. There is still the overhead of going across the network to
talk to Redis, but the net improvement is vast.

This commit only caches the `GET /service` response, but is written in
such a way that we can easily expand to caching other responses down the
line.

The tradeoff here is that our code is more complex, and we risk
introducing edge cases where a cache becomes stale. The mitigations
against this are:
- invalidating all caches after 24h so a stale cache doesn’t remain
  around indefinitely
- being careful when we add new stuff to the service response

---

Some indicative numbers, based on:
- `GET http://localhost:6012/services/<service_id>/template/<template_id>`
- with the admin app running locally
- talking to Redis running locally
- also talking to the API running locally, itself talking to a local
  Postgres instance
- times measured with Chrome web inspector, average of 10 requests

╲ | No cache | Cache service | Cache service and user | Cache service, user and template
-- | -- | -- | -- | --
**Request time** | 136ms | 97ms | 73ms | 37ms
**Improvement** | 0% | 41% | 88% | 265%

---

Estimates of how much storage this requires:

- Services: 1,942 on production × 2kb = 4Mb
- Users: 4,534 on production × 2kb = 9Mb
- Templates: 7,079 on production × 4kb = 28Mb
2018-04-10 12:58:35 +01:00
Leo Hemsted
31112c9ecf run gunicorn with eventlet
this massively increases the horizontal parallellability by using async workers
2018-02-01 14:56:52 +00:00
Alexey Bezhan
c550c686d1 Replace manifest user-provided services with environment variables
Variable values are populated from the credentials by the `generate-manifest`
make target.
2018-01-09 14:17:03 +00:00
Leo Hemsted
2cd77e628e remove wsgi.py - always serve with whitenoise
We're now running our app as a wsgi app locally, so don't need to
distinguish between the two processes by having wsgi and application.py
whitenoise just serves static files nicely - we don't lose anything
by doing that locally.
2017-11-07 11:50:13 +00:00
Athanasios Voutsadakis
79752d2754 Configure gunicorn errorlog
Related: alphagov/notifications-api/pull/1274
2017-09-22 15:41:41 +01:00
Leo Hemsted
0850f5dd22 add template preview service to cf manifest 2017-04-18 16:43:55 +01:00
bandesz
3e1553489b Increase memory for PaaS 2017-03-06 14:48:11 +00:00
bandesz
b148a0a6a0 Add awslogs logging for PaaS 2017-02-16 14:19:37 +00:00