Setup and config Go environment on Ubuntu 16.04 and Centos 7

Recently somebody have some questions for me.

  • Why i can’t run go get ?
  • How to change workspace project with Go ?
  • Why after i exit session on terminal then all config is reset and go command not found ?

Ok, the following below i will detail, how i installed Go ? You can get more information about it at page https://golang.org/doc/install. 

Step 1 : Download the latest or the stable version Go. Currently i use Go version 1.9.1 for my project.
wget https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz

Step 2: Check Go is installed on system and clear it.
sudo rm -rf /usr/local/go

Step 3 : Extract compress file to folder “/usr/local”
sudo tar -C /usr/local -xzf go1.9.1.linux-amd64.tar.gz

Step 4 : Setup environment for user (the step is very important)
[Centos] Add the configuration to file “~/.bashrc”
[Ubuntu] Add the configuration to file “~/.profile”

export GOPATH=/usr/local/go/workspace
export GOROOT=/usr/local/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Apply all config environment with command

[Centos]
source ~/.bashrc

[Ubuntu]
source ~/.profile

******* Note *******
GOPATH : this is the directory where you want to save projects.
GOROOT : the directory of root Go (Step 3)
*******************

Step 5 : Verify installation
Check current version Go
go version

Selection_022

Show all information configuration of Go
go env
Selection_019

Done ! If you have a question for me please inbox facebook, linkedIn, we can discuss about it.
Good luck!

Circuit Breaker pattern – Overview Part 1

In our system, we have many services and it is allocated at difference servers. We have used RPC (Remote Procedure Calls) to call between services but I have a problem about failure with remote call.In a distributed environment calls to remote resource and services can fail due to transient faults such as slow network connections, timeouts or the resources being over committed or temporary unavailable. So i started to learn about “retry pattern” and i have found “Circuit breaker” as pattern give me a solution for my problem.

I have set some goals as follows

+ Learn about “Circuit breaker pattern” model architecture and how to work.
+ Looking for some libraries support this pattern.
+ Practice pattern with Java and Golang.

In the part, i focus into overview about solution and explain how to it work ?

The Circuit pattern can prevent an application from repeatedly trying to execute an operation that’s likely to fail. Allowing it to continue without waiting for the fault to be fixed and it also enables an application to detect whether the fault has been resolved. The pattern will try execute operation and update status service when the problem to have been resolved.

Circuit breaker acts as a proxy for operations that might fail. The proxy should monitor the number of recent failure that have occurred, and use this information to decide whether to allow the operation to process.

A operation that might fail have 3 type state

Close :
+ The request invoke from application is routed to the operation.
+ Reset failure counter number of requests is failed.
+ If the number of recent failure exceed a specified threshold, state Close –> Open.

Open :
+ When operation change state from Close -> Open –> start timeout timer.
+ The request invoke from application fails immediately and an exception is returned to the application.
+ When this timeout timer is expired, state Open –> Half-Open.

Half-Open :
+ A limited number of requests from the application are allowed to pass through and invoke the operation.
+ If these requests are successful, state Half-Open –> Close.

circuit-breaker-diagram

When to use this pattern 
To prevent an application from trying to invoke a remote service or access a shared resource if this operation is highly likely to fail.

When should’t use this pattern 
Handling access to local private resource, such as in memory data structure.  As a substitute for handling exceptions in the business of your applications.

The next post, i will write how to implement circuit breaker pattern with java, thank you.