2

When deploying a bare-bones Django application using Zappa, I'm finding my TTFB (Time To First Byte) times are between 280-800ms however generally around 700ms. Which is far too long for a website.

Other people seem to be getting much better response times such as "125ms to 500ms ... (probably averaged about 175ms)" (https://www.reddit.com/r/django/comments/44r55j/announcing_djangozappa_serverless_django_on_aws/).

To reproduce my issue:

pip3 install django-admin
mkdir test
cd test
virtualenv .env
source .env/bin/activate
pip3 install django zappa
django-admin startproject zaptest
zappa init (and choose all defaults)
zappa deploy dev

And go to the URL supplied.

Any advice on how to speed this up would be much appreciated.

Luke
  • 2,851
  • 1
  • 19
  • 17
  • 1
    Read about Lambda cold starts versus warm starts. The sequence of steps you describe above will result in a cold start, with a long and mostly unavoidable time to first byte. Subsequent hits to the same instance will be significantly faster. Any attempt to measure and control Lambda performance must take this distinction into account. – Kevin Christopher Henry Jul 04 '18 at 04:34
  • @KevinChristopherHenry sorry I should have explicitly mentioned that the average response time of 700ms was from repetitively loading the page. Not waiting for the service to cool down. Zappa by default has a 4-minute cron to keep the service warm as well. – Luke Jul 04 '18 at 05:03
  • Did you try setting the keep-warm to 1 minute? – Brian Destura Sep 12 '18 at 03:13
  • @bdbd I'm uncertain if I tried changing keep-warm to 1 minute. However, I was reloading a page multiple times within a minute. I don't think the project was cold starting, since that was considerably slower. – Luke Sep 12 '18 at 04:04
  • Setting it to 1 minute should help. Have a read at: https://medium.com/thundra/dealing-with-cold-starts-in-aws-lambda-a5e3aa8f532 – Brian Destura Sep 12 '18 at 06:21
  • Also is your lambda inside a VPC? – Brian Destura Sep 12 '18 at 06:24
  • @bdbd thanks for all your suggestions. I wasn't running lambda in a VPC. I tried re-deploying before testing your 1 minute keep-warm suggestion. However, I couldn't get it to go above 200ms before making your change. I'm guessing I just kept getting deployed on overloaded servers. – Luke Sep 12 '18 at 22:58
  • The default zappa configuration deploys with 512mb ram setting. As AWS puts it: Your function is allocated CPU proportional to the memory configured. Setting to to higher values 1856mb should improve on cold start time (linear). – ambientlight Nov 23 '18 at 14:17

1 Answers1

0

The issue turned out to be the initial TLS handshake is slow and nothing to do with Zappa or Lambda. I was hosting in the US even though I live in Australia because it was a test system and its cheaper to host in the US. Upon moving to Australia the speed improved dramatically.

Luke
  • 2,851
  • 1
  • 19
  • 17