Google Cloud App Engine WebSocket connections close after about an 1 hour - google-app-engine

I have a golang gorilla websocket server hosted on Google App Engine (GAE) that randomly disconnects connected clients after about an hour of being connected (without any activity).
I checked GAE logs and compared timestamps of close events (code 1006) and noticed that the time differences between opening and closing connections are all nearly the same (~60.1 minutes).
Is there a proper way to fix this issue (example: update associated nginx config) for Google App Engine?
I'm fairly certain that this an issue with GAE as I'm unable to reproduce this issue locally/in-development.
I couldn't find any other good ways of hosting an autoscaled/managed server that supports the websocket protocol.
My alternative hosting choice may be kubernetes, but the costs are much higher than GAE AFAIK and K8s is slightly more difficult to manage.
I found a few related stackoverflow links with no proper solutions (mostly migrations to other services or hacks)
example: GAE App Engine Websocket clients are disconnected after 1 hour

It's well documented on GCP docs :
WebSockets are always available to your application without any additional setup. Once a WebSockets connection is established, it will time out after one hour.
I wouldn't suggest creating a Websocket server on a serverless platform because these products tend to scale down over time when there's no requests on it so you cannot guarantee that it will continue holding the connection (also along with the hard limit mentioned).
You can host your Websocket server on Compute Engine. In fact, GAE Flex uses Compute Engine autoscaler. Here's a link if you're interested to see how it works.

Related

Parse Platform LiveQuery / Websockets + Google AppEngine + CloudFlare Unreliable delivery

Im running Parse Server with LiveQuery enabled.
I built a chat app and locally in the browser it works pretty fine and super reliable.
When I deploy to app engine its not so reliable, i send 2 or 4 messages and maybe they deliver or maybe after the 5th message they all deliver at once. Im not sure whether this is some issue with latency or Google App Engine or the fact that I put Cloudflare on front of app engine. I am running only 1 app engine version/instance of the backend websocket API
Im not entirely sure how to debug this issue either, does anyone know of any limitations with AppEngine and/or Cloudflare with regard to websockets or in general websocket reliability and latency

Django with Cloud SQL on GAE Flexible

My Django app is working on GAE with Cloud SQL(MySQL).
By using New Relic Monitoring, I tracked requests done by my app to www.googleapis.com.
I don't know those requests. Can somebody explain this behavior?
(app connecting with cloud proxy)
As merely described here, there are various processes running in the instance along side (with?) your application... scaling, billing, logging, etc. Communication with other Google Cloud Services (like the ones I previously mentioned) is mainly done through Google Cloud APIs. Since App Engine is a managed Platform as a Service, this management needs to be done somehow... a myriad of REST API requests and responses do this. Partly through the www.googleapis.com endpoint.
You don't have to worry, though... your application's performance is not affected by this, nor your billing account.

Switching across region for failover

We are trying to build a fault tolerant architecture. The objective is to switchover to solution on another zone in case of failure. The following is the situation
Our solution is build over Google AppEngine using Java. We use datastore as db.
Currently it is deployed on a X zone of AppEngine.
We have now replicated the same environment on a different region.
When a failover occurrs we would like to forward the request to the replicated zone.
How to achieve it? It seems their is options for Compute Engine but our solution is using AppEngine where instance are managed by the Google Cloud.
If you have a custom domain you can deploy your failover to www2.example.com and just forward the request with a DNS server if your main app is completely down, or let the main app redirect to the failover if the main app itself finds it is failing.

Behaviour when doing requests between 2 Google AppEngine apps

We run 2 apps on Google AppEngine, one in Python, and one in Java.
The Python app faces the internet and serves browser users or API calls from our smartphone app.
The Python app often communicates with the Java app, which offers workflow engine services.
The Java app is never accessed directly from the internet. This is similar to a service oriented architecture.
Our Java app is configured with 1 resident instance.
However, we often see that when the Python app sends a request to the Java app (which is doing nothing at that moment), that a new Java instance is spawned, instead of having the resident instance serve the request. This way, latencies up to 10 seconds were discovered, whereas the request handling itself takes less than 1 second.
Could it be possible that Google considers a request from one appengine app to another one, as a sort of backend workload, for which throughput is more important than latency? Are there different policies for requests coming from the internet versus requests coming from Google internally (defered methods, cron, ... maybe inter-appengine requests also resorts in this category, which is maybe not always correct).
Google recommended me to run the Java app as a backend of the Python app, and in fact have only 1 single Appengine app, instead of 2.
Some information in this thread:
https://groups.google.com/forum/?fromgroups=#!topic/google-appengine/8O7K3cFzBbY
Any advice on how to force appengine resident instances handle incoming requests, rather than spawn and warm up new instances, which might be good for throughput, but bad for latency?
Have tried to add <threadsafe>true</threadsafe> element to appengine-web.xml on your java app?

Make Google App Engine as Load Balancing Server

I'm wondering if anyone knows any script in Python or Java to setup Google App Engine as Load Balancer server?
I choose GAE, because of 100% uptime and free, so it would be the best to setup as Load balancer.
So what I want to do is set up a GAE app (a load balancer application) in "www.domain.com" - using Google Apps, it will share the load to all my servers (with round-robin, or any technique), but when all servers are down, show maintenance page which is host in GAE.
Is this possible?
You could do it, but you'd
incur extra latency by requiring an extra hop from google app engine to your servers
have all your servers public to the web, since otherwise google app engine won't be able to redirect to them Edit: apparently this is incorrect. See Nick Johnson's comment below!
have to implement something in google app engine to keep track of what servers you have up and how and when to route to them
Seems like it might not be worth it, but it'd be cool if you did it and posted some numbers about how it works!

Resources