Home > Software design >  Reducing latency in Google App Engine request
Reducing latency in Google App Engine request

Time:08-28

I am looking to add an Authentication endpoint to determine whether a user is logged in. Essentially every single service will call this (either internally or externally). To see what the starting latency of using Google App Engine is, I added a basic endpoint in Flask:

main.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def test():
    return 'My Default Service - V1 -- ok!'

app.yaml

service: default
runtime: python39

requirements.txt

Flask==2.1.3

And going to the endpoint at https://premiere-stage2.uk.r.appspot.com/ takes on average, about 0.27s. While this is normally a fine response time, I am looking for an ultra-low-latency way to handle a specific endpoint. Taking as a reference, here is doing a search on Algolia:

>>> t0=time.time();index.search('xxxxxxxxxx');print(time.time()-t0)
{'hits': [], 'nbHits': 0, 'page': 0, 'nbPages': 0, 'hitsPerPage': 20, 'exhaustiveNbHits': True, 'exhaustiveTypo': True, 'query': 'xxxxxxxxxx', 'params': 'query=xxxxxxxxxx', 'processingTimeMS': 1}
0.03498721122741699 

The typical response times are about 0.035-0.04s, or about 10x faster than the endpoint I currently have (which is doing nothing).

Are there any ways to improve the latency of a Google App Engine product, or is it just not possible to get to something under 0.1s response time using GAE?


Update: I also did the same for a Node environment and got the same response times, around 0.25s:

app.js

'use strict';
const express = require('express');
const app = express();
app.get('/', (req, res) => {
  res.status(200).send('Hello, world!').end();
});

app.listen(8080, () => {});
module.exports = app;

app.yaml

service: default
runtime: nodejs14
instance_class: F4_1G

package.json

{
  "engines": {
    "node": "14.x"
  },
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "^4.17.1"
  }
}

CodePudding user response:

One thing to keep in mind is that you can take advantage of HTTP's keep-alive:

Connection: keep-alive

With this you can get responses under 0.1s:

>>> import time,requests
>>> session = requests.Session()
>>> t0=time.time();session.send(requests.Request('GET', url='https://premiere-stage2.uk.r.appspot.com/').prepare());print(time.time()-t0)
<Response [200]>
0.2976038455963135
>>> t0=time.time();session.send(requests.Request('GET', url='https://premiere-stage2.uk.r.appspot.com/').prepare());print(time.time()-t0)
<Response [200]>
0.09582376480102539

Now you'll consistently see responses at about 0.95s.

CodePudding user response:

I suspect you can't get 0.1s response times with GAE. GAE is a general purpose PaaS that works great for a wide variety of web apps. Most people don't care about the response times you are looking for.

Have you researched how people get such short response times? I suspect it involves things like pre-rendering content and edge caching. You can't get that kind of stuff with a hello-world PaaS set up.

  • Related