GCP Serverless Function in Java with 15Mb RAM
The blog is more about experimenting with Java Native build to achieve less RAM use. Usually, when using Java as a runtime for Google Cloud functions ( https://cloud.google.com/functions/docs/concepts/java-runtime ) the average RAM footprint is about 140 MB for a simple REST API Jax-RS based endpoint with JSON (text) static response. For example, the same example in Golang (one HTTP GET method) with JSON response is around 30 MB RAM. To try to achieve less RAM footprint with Java (e.g. to use 128 MB GCP tier), let us try to use: - Java Socket as very simple HTTP server - GraalVM Native build - Docker - Google Cloud Run to use custom Docker image as an app Java code Source code : https://github.com/ahndmal/http-simple-sock-native We create ServerSocket and accept connections on port 8080: try ( ServerSocket serverSocket = new ServerSocket ( 8080 )) { System . out . println ( ">>> Server started on port 8080" ); while ( true ) { Socke...