Saturday, 7 March 2020

Git Branches and Development/Deployment Model

Model 1: Simple Git development/deployment model:
  • 'dev' branch: Development branch
    • May contain errors, bugs
    • Developers merge in
    • Testers test
      • Fail: No merge to 'master' branch
      • OK: Merge to 'master' branch
  • 'mater' branch: Production branch
    • No errors, no bugs
    • Deploy by schedule
Model 2: Safe (2 times no errors, no bugs) Git development/deployment model:
  • 'dev' branch: Development branch
    • May contain errors, bugs
    • Developers merge in
    • Developers merge to 'staging'  branch (Extra step compared to Model 1)
  • 'staging' branch: QA/QC branch
    • No errors, no bugs (Extra safety compared to Model 1)
    • Testers test
      • Fail: Revert those commits from 'dev' branch
      • OK: Merge to 'master' branch
  • 'master' branch: Production branch
    • No errors, no bugs
    • Deploy by schedule

HTTP Response Codes and Possible Failure Issues

HTTP response codes from 1xx to 5xx and their possible failure issues:

Out-going request:
  • Own server --> ISP proxies --> Customer proxy (Nginx) -->  Customer server
Inward request:
  • Customer server --> ISP proxies --> Own proxy (Nginx) --> Own server
1xx:
  • Exactly a response from server
  • No failures, informational response
2xx:
  • Exactly a response from server
  • Successful response from server
3xx:
  • Response from server or proxies
  • HTTP redirect
  • Possible issues:
    • Bad redirect by server, for example, infinite redirection
    • Bad redirect by proxies, for example, inifinite redirection
4xx:
  • Exactly a response from server
  • Error due to client request data
  • Possible issues:
    • Bad headers
    • Bad parameters in URL
    • Bad data in POST body
5xx:
  • Response from server or proxies
  • Error due to server side
  • Possible issues:
    • Server code error, exception, crash, etc.
    • Proxy (Nginx) fails to proxy_pass to a service
Timeout:
  • Target IP, domain, subdomain don't exist
  • Target machine having firewall that dropouts connections
  • No internet connection
  • Server doesn't respond
Reference:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Wednesday, 4 March 2020

RAM Usage Display: Free, Cached, Used

Notes about RAM usage on computer:
  • Free RAM: 
    • The amount of RAM never been used
  • Cached RAM: 
    • The amount of RAM ever been used to load programmes, but OS doesn't want to free them, OS keeps them to avoid loading programmes from disk again.
    • When free RAM is not available, OS will throw away some of the Cache RAM to make free space for allocation.
  • Used RAM: 
    • The amount of RAM allocated to programmes, can't be used for other ones.

Tuesday, 3 March 2020

Redirect All Tornado Logs to stdout and stderr

Tornado by default steals all stdout and stderr to its logging. This is crazy, one can't even do 'print'.

Redirect all back to stdout and stderr:
import logging
import sys

import tornado.log
from tornado.options import options

def setup_logging_to_stream(stream, log_level):
  logger = logging.getLogger()
  channel = logging.StreamHandler(stream)
  channel.setLevel(log_level)
  channel.setFormatter(tornado.log.LogFormatter())
  logger.addHandler(channel)


def setup_logging(log_level=None):
  if log_level is None:
    log_level = getattr(logging, options.logging.upper())

  logger = logging.getLogger()
  logger.setLevel(log_level)

  setup_logging_to_stream(stream=sys.stdout, log_level=log_level)
  setup_logging_to_stream(stream=sys.stderr, log_level=logging.ERROR)

setup_logging();

Reference:
https://gist.github.com/malexer/06fd8f6530a02fddc5feb7c1f2628799

Monday, 2 March 2020

ML Libraries

TensorFlow 2:
  • Popular, big community, fast, by Google, works with CPU, GPU, TPU
  • Recommended!
PyTorch:
  • Somehow wrong design, activation functions should be inside layers
  • Recommended if accepting the wrong design.
Chainer:
  • Similar to PyTorch, Japanese library, mostly only Japanese people use.
Theano:
  • In maintenance mode, no longer development.
  • Avoid using this library, no longer active.
CNTK:
  • Works with Ubuntu 16 only, relies on a lib that exists only on Ubuntu 16, or build the lib by oneself otherwise.
  • Is Microsoft abandoning this lib? should work out-of-the-box on any platform.