App Engine vs Cloud Functions

Both Cloud Functions (CFs) and Google App Engine (GAE) are designed to build “microservice architecture” in the “serveless” environment.

Google says that Cloud Functions is basically for SERVERLESS FUNCTIONS & EVENTS where as App Engine is for SERVERLESS HTTP APPLICATIONS. However,when I read this short description I am still confused since if I am running SPA application what prevents me to use just CFs for my serverside code? When exactly would use GAE instead of CFs?

I made a small investigation on this and here are my findings.

Little bit more longer description from Google:

Cloud Functions

An event-driven compute platform to easily connect and extend Google and third-party cloud services and build applications that scale from zero to planet scale.

Use Cases

  • Asynchronous backend processing
  • Simple APIs (like one or two functions, not RESTful stuff)
  • Rapid prototyping and API stitching

 

 

App Engine standard environment

A fully managed serverless application platform for web and API backends. Use popular development languages without worrying about infrastructure management.

Use Cases

  • Web applications
  • API’s like Mobile and SPA backends

 

 

 

I found this answer from StackOverflow which I am updating here with few of my edits.

When creating relatively complex applications, CFs have several disadvantages compared to GAE.

  • Limited to Node.JS, Python, and Go. GAE supports also .NET, Ruby, PHP, Java.
  • CFS is designed for lightweight, standalone pieces of functionality, attempting to build complex applications using such components quickly becomes “awkward”. Yes, the inter-relationship context for every individual request must be restored on GAE just as well, only GAE benefits from more convenient means of doing that which aren’t available on CFs. For example user session management, as discussed in other comments
  • GAE apps have an app context that survives across individual requests, CFs don’t have that. Such context makes access to certain Google services more efficient/performant (or even plain possible) for GAE apps, but not for CFs. For example memcached.
  • the availability of the app context for GAE apps can support more efficient/performant client libraries for other services which can’t operate on CFs. For example accessing the datastore using the ndb client library (only available for standard env GAE python apps) can be more efficient/performant than using the generic datastore client library.
  • GAE can be more cost effective as it’s “wholesale” priced (based on instance-hours, regardless of how many requests a particular instance serves) compared to “retail” pricing of CFs (where each invocation is charged separately)
  • response times might be typically shorter for GAE apps than CFs since typically the app instance handling the request is already running, thus:
    • the GAE app context doesn’t need to be loaded/restored, it’s already available, CFs need to load/restore it
    • the handling code is (most of the time) already loaded, CFs’ code still needs to be loaded. Not to sure about this one, tho, I guess it depends on the underlying implementation.

Note that nothing prevents us from mixing both notions. An AppEngine application can launch jobs through cloud functions

Summary

Use Cloud Functions (CFs) for “tasks” and use Google App Engine (GAE) for “full applications”.

 

 

Advertisements

ERROR: gcloud crashed (ValueError): unknown locale: UTF-8

I was getting this error on gcloud CLI when trying to deploy Cloud Functions to Google Cloud.

Here’s the quick fix – add these lines to your ~/.zshrc or ~/.bash_profile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Create, Run and Delete Container from Dockerfile

First, lets make a simple “hello world” that runs and outputs nodejs command from the container.

STEP 1

Create folder and put following files on the folder:

Dockerfile

# Specify a base image
FROM node:alpine
WORKDIR ‘/app’
# Install some dependencies
COPY ./package.json ./
RUN npm install
COPY ./ ./
# Default command
CMD [“npm”, “start”]
package.json
{
  “dependencies”: {
    “express”: “*”
  },
  “scripts”: {
    “start”: “node index.js”
  }
}
index.js
const express = require(‘express’);
const app = express();
app.get(‘/’, (req, res) => res.send(‘Hello World!’))
app.listen(8081, () => {
  console.log(‘Listening on port 8081’);
});
This will create a simple webserver that is listening port 8081 spitting out “Hello world!”
STEP 2
Build Docker Image and Run it
docker build .
This will create an image from the Dockerfile to your computer.
Tip: You can have multiple configurations, for example if you have different configuration for local development. Then use -f -flag to point to that like this: docker build -f Dockerfile.dev .
On the previous command docker created an image for you and passed you the image ID. It looks something like this on the console:
Successfully built 6bf0f35fae69
Now, you need to take this image ID and run like this:
docker run 6bf0f35fae69
Docker container is now running but we created the web server. The host has no idea how to access to this container so we need to do some port mapping.
Stop the container with CTRL+C
Then run the same command but with port mapping
docker run -it -p 8081:8081 6bf0f35fae69
On the port parameter ports are mapped as host:container
STEP 3
View and delete container
docker ps -a
docker rm CONTAINERID
To remove all containers
docker rm $(docker ps -a -q)
Check existing dockers on your system: docker images

YouTube channels to learn Electronics and Hardware

Enjoy some of YouTube’s best educational channels run by “edutainers” and see for yourself how they can spark your curiosity for learning more online:

Electronics and hardware

Louis Rossmann
Louis Rossman https://www.youtube.com/channel/UCl2mFZoRqjw_ELax4Yisf6w Routinely shows bench scope detail of him doing circuit troubleshooting and replace of “no user serviceable parts” modern surface mount Apple stuff, but in the process shows good heart and entertaining moxie.

EEVBlog
EEVBlog (David L. Jones) https://www.youtube.com/user/EEVblog Likes to take things apart and people send him things, but he is a great teacher and gives an amazing does of theory and design practice, and (very rare!) his electronics design knowledge spans part and practice back to the early 1970s.

bigclivedotcom
bigclivedotcom https://www.youtube.com/user/bigclivedotcom/videos Famous for his teardowns of the most ludircous and trashy designs, he’s a maverick experimenter who plods along and pokes and prods and touches things he shouldn’t, just like you would.

AvE
https://www.youtube.com/user/arduinoversusevil General engineering

Strange Parts 
https://www.youtube.com/channel/UCO8DQrSp5yEP937qNqTooOw Interesting electronics

Electroboom
https://www.youtube.com/user/msadaghd/ Interesting electronics

Ben Eater
https://www.youtube.com/user/eaterbc Electronics, breadboards, computer logic.

bigclivedotcom
https://www.youtube.com/user/bigclivedotcom examines / fixes electronics

 

 

 

Restart Application Pool in Powershell and write it to EventLog

Sometimes on Continuous Integration or other automated scenarios you want to restart Application pool in order to recycle everything clean. This can be done by calling Powershell command Restart-WebAppPool like this: “Restart-WebAppPool AppPoolNameHere”. But you might also want to write log entry to EventLogs so you know what is going on.

In order to write to the event log, one can use the Write-EventLog cmdlet but there are mandatory parameters needed to write the event log information. These are:

  • LogName
  • Source
  • EventID
  • Message

If you want to create an entry log message “Format was called” into the Application Log and store this into your custom source “MyScript” with a custom event ID like “3001”, you will need to type it as:

Write-EventLog -LogName Application -Source MyScript -EventId 3001 -Message "Format was called"

If you have not registered your custom event source, you will encounter an error. In order to register a custom event source, you will need to call the New-EventLog cmdlet like the example below:

New-EventLog -LogName Application -Source MyScript

After this you can call Write-eventLog as following:

Write-EventLog -LogName Application -Source MyScript -EventId 3001 -Message “Format was called”

Restart Windows in 1 hour or certain time

tldr;

  • Open Powershell as Admin
  • Type: Start-Sleep 3600 ; Restart-Computer -Confirm:$false <enter>

 

I work on RDP a lot against Windows Machines and sometimes there are updates and downloads what I need to do and afterwards update. Or perhaps I need to restart in certain time.

Basically what start-sleep does is pause the process for the number of seconds that you specify. The semicolon is like having another line in the code so it will execute what is next, which in this case is restart-computer. Since you may not be logged into the server or it may be at a lock-screen, you will need to include the -confirm:$false otherwise it may not execute.

If you want to restart on certain time

  • shutdown -r -t ([decimal]::round(((Get-Date).AddDays(1).Date.AddHours(3) - (Get-Date)).TotalSeconds))

This will get the number of seconds between the time the script is ran and 3:00AM the following day (on the server time). It then passes the result to shutdown.exe. Obviously this is designed to be ran before midnight. Remember “-r” so it is actually restarting instead of just shutting down.

Xcode 9 and Xcode 10 Side-by-side

I have been working on Ionic 4 project recently and I hit to wall because since Cordova has compatibly issues with the latest Xcode (10). After headaches with compiling the iOS project I returned to great Ionic documentation about iOS setup where it of course clearly says on the top:

We recommend using XCode 9. Xcode 10 support in Cordova is still a work-in-progress. See this issue for details.

So, yes. You need Xcode 9 if you want to work on Corova still (as writing in Feb 8 2019.) Luckily it is possible to run multiple versions of Xcode on the same machine. You simply need to copy additional versions to Applications with different name. Like this: