Golang on Cloud

1-click AWS Deployment    1-click Azure Deployment

Overview

Go language is developed at Google in the year 2007 is a programming language by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically-typed language having syntax similar to that of C. It provides garbage collection, type safety, dynamic-typing capability, many advanced built-in types such as variable length arrays and key-value maps. It also provides a rich standard library. The Go programming language is used in some of the Google’s production. Golang is one of the most trending languages among the developer community as it provides the best of both worlds, by outstanding a balance between dynamic and statically compiled languages. The code is easy to read, the requirement is brief, and it includes a built-in web server.

Golang was made to help solve problems faced by developers at google. At Google, lots of big programmes are built for big server software that runs on enormous clusters. Before Go, Google was using languages like C++ and Java to resolve difficulties, but these languages didn’t really have the flexibility and hardship of construction that was required for problems of such scale. Keeping these things in mind, a few years ago Ken Thompson and Robert Greaser thought about building a new language that would be good for these kinds of problems, and hence Golang was born. Essentially, if we are trying to solve a problem of enormous scale or just need efficient and scalable code.

Here are the few problems that we are facing with Python, Java, C/C++ programming languages:

  • Python: It is easy to use but slow in compare to Golang.
  • Java:It has very complex type system.
  • C/C++: It has slow compilation time as well as complex type system.
  • Also, all these languages were designed when multi-threading applications were rare, so not much effective to highly scalable, concurrent and parallel applications.
  • Threading consumes 1MB whereas Goroutine consumes 2KB of memory, hence at the same time, we can have millions of goroutine triggered.

The present languages have been good enough for large scale programming, but there have been vast changes in the computing environment in the last span which has included a lot of networking, a lot of cluster computing or the cloud as common folk might know it by. The languages that were being used to implement services until now are at least 10-20 old, so there are a lot of properties of a modern computing environment that these languages don’t address directly. Hence, having a modern language that works really well in the modern computing environment is truly important, but we also want it to be resourceful because we are going to be running these on hundreds or maybe even thousands of machines. Also, we don’t want to leftover resources by having an incompetent translator or some of the problems that generally come up with virtual machine operations.

 

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.Go (also called GoLang) is an open source, general-purpose programming language developed by Google engineers to create dependable and efficient software. Most similarly modeled after C, Go is statically typed and explicit.

Benefits of Go

  • Quick compilation and execution speed
  • No virtual machine (VM) is needed
  • Portability
  • Lightweight goroutines that support concurrency
  • Interfaces enable loosely coupled systems
  • Automatic garbage collection
  • Memory safety
  • Independent error handling
  • Extensive built-in libraries

Features

Features of Golang:

 1.Concurrency

Go proposes few great concurrency primitives and makes it extremely easy to implement a concurrent system. Go supports this at the language level and concurrency is a first-class citizen. The fundamental unit for this in Go is a go routine. Doing something in a Go routine means they need to be able communicate with other routines. To achieve this, Go provides channels. Channels are conduits that allow two concurrent Go routines to talk to each other by sending and receiving values. The <- syntax can be used to send a value into a Go routine, while the <-channel syntax can be used to read something from a channel.

2. Simplicity and Consistency

Go is a comparatively an easy to understand language and was designed with a very minimalistic approach. The standard library contains most things including a web server! Small features of the language help achieve this. For example – If the function name in a Go package starts with an uppercase letter, it is exported while all functions with lower case names are not. Go does not support generics, although it is strongly and statically typed. While this is debatable, it was done to keep the language simple and to avoid intricacy. The standard library is exemplary and the packages are reliable. The language does restrict the way you can do some things, but this compromise in flexibility means more simplicity. It might mean writing a bit more code but there are some clear solutions. Consistency is enforced by the language and it goes a long way in contributing to readability and maintainability. There are fluent ways of doing things in Go and these come directly from the Go team based on the language design. effective go showcases some of these. go-fmt allows formatting Go code and is rooted in the same approach.

3. Go is object oriented

Coming from other languages, it may seem like Go is not object-oriented. It does not provide the class keyword and has no support for inheritance. This might seem bizarre. However, Go’s replacement for classes are structs. A struct may have any number of properties and methods defined on them. Go goes for composition over inheritance. This is achieved by embedding structs and interfaces. This allows types to borrow functionality from other structs and interfaces. it’s a simpler fragmented down approach to OO and it works! More traditional OO language users may glare, but breaking components down into struct types and composing them where required is graceful.

4. The Compiler

Go’s compiler is super-fast. It is easily possible to compile a large Go program within a few seconds. The fact that the language syntax is so simple means that compilation is much quicker. The language was designed to be easily parseable without a symbol table. Go is also statically linked which means that the compiler invokes a linker in the last step that resolves all library references. This means we’d get one binary executable after compiling a Go program with no external dependencies. While this means the executable, itself is bigger in size, it is faster and also more portable. Go also compiles to native machine code negating the need for environments such as JVM.

5. Pointers

I thought I’d never have to use pointers after my university days, learning C. Go aims to provide a modern equivalent of C in some areas and has brought back pointers. Most modern languages do not provide pointers; however. pointers help solve a lot of common issues and play a far more important role when it comes to memory layout and building low level system tools. Pointers solve problems that often make you scratch your head or when you expect something to be updated to a new value, but it doesn’t. However, using pointers in a wrong way could have bad implications.

Go is a minimalist language, and that’s a consecration.

The formal Go language specification has abundant examples, and is impartially easy to read. A skilled programmer could probably learn Go from the specification alone. The core language consists of a few simple features that can be combined in a relatively small number of ways. This makes it easier to learn the language, and to read and write programs. When you add new features to a language, the complexity doesn’t just add up, it often multiplies: language features can interact in many ways. This is a significant problem – language complexity affects all developers

Some Go features are mentioned below:

  • The built-in frameworks for testing and profiling are small and easy to learn, but still fully functional. There are plenty of third-party add-ons, but chances are you won’t need them.
  • It’s possible to debug and profile an optimized binary running in production through an HTTP server.
  • Go has automatically generated documentation with testable examples. Once again, the interface is minimal, and there is very little to learn.
  • Go is strongly and statically typed with no implicit conversions, but the syntactic overhead is still surprisingly small. This is achieved by simple type inference in assign­ments together with untyped numeric constants. This gives Go stronger type safety than Java (which has implicit conversions), but the code reads more like Python (which has untyped variables).
  • Programs are constructed from packages that offer clear code separation and allow efficient management of dependencies. The package mechanism is perhaps the single most well-designed feature of the language, and certainly one of the most overlooked.
  • Structurally typed interfaces provide runtime polymorphism through dynamic dispatch.
  • Concurrency is an integral part of Go, supported by goroutines, channels and the select statement.

Code transparency

  • You always need to know exactly what your coding is doing,
  • and sometimes need to estimate the resources (time and memory) it uses.

Go tries to meet both of these goals.

The syntax is designed to be transparent and there is one standard code format, automatically generated by the fmt tool.

Another example is that Go programs with unused package imports do not compile. This improves code clarity and long-term performance.

I suspect that the Go designers made some things difficult on purpose. You need to jump through hoops to catch a panic (exception) and you are forced to sprinkle your code with the word “unsafe” to step around type safety.

Python comparison

The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transparent: it’s easy to miss that the time complexity is O(n), where n is the number of elements in the list.Go doesn’t have a similar utility function. This is definitely less convenient, but also more transparent. Your code needs to explicitly state if it copies a section of the list. See 2 ways to delete an element from a slice for a Go code example.

Java comparison

Code transparency is not just a syntactic issue. Here are two examples where the rules for Go package initialization and program execution order make it easier to reason about and maintain a project.

  • Circular dependencies can cause many unwanted effects. As opposed to Java, a Go program with initialization cycles will not compile.
  • When the main function of a Go program returns, the program exits. A Java programs exits when all user non-daemon threads finish.

This means one need to study large parts of a Java program to understand some of its behavior. This may even be dreadful if we use third-party libraries.

Compatibility

A language that changes abruptly, or becomes unavailable, can end your project. Go 1 has succinct and strict compatibility guarantees for the core language and standard packages – Go programs that work today should continue to work with future releases of Go 1. Backward compatibility has been excellent so far. Go is an open source project and comes with a BSD-style license that permits commercial use, modification, distribution, and private use. Copyright belongs to The Go Authors, those of us who contributed to the project. There is also a patent grant by Google.

Python comparison

If you’re a Python developer, you know the pain of having to deal with the differ­ences between Python 2.7.x and Python 3.x. There are strong reasons for choosing Python 3, but if you depend on libraries that are only available for an older version, you may not be able.

Java comparison

Java has a very good history of backward compatibility and the Compatibility Guide for JDK 8 is extensive. Also, Java has been freely available to developers for a long time. Unfortunately, there are some dark clouds on the horizon with the Oracle America, Inc. v. Google, Inc. legal case about the nature of computer code and copyright law, and Oracle’s new Java licensing model.

Performance

The exterior of Go is far from flashy, but there is a fine-tuned engine underneath. It makes little sense to discuss performance issues out of context. Running time and memory use is heavily influenced by factors such as algorithms, data structures, input, coding skill, operating systems, and hardware. Still, languageruntime and standard libraries can have a large effect on perfor­mance. This discussion is limited to high-level issues and design decisions.

First, Go is a compiled language. An executable Go program typically consists of a single standalone binary, with no separate dynamic libraries or virtual machines, which can be directly deployed.

Size and speed of generated code will vary depending on target architecture. Go code generation is fairly mature and the major OSes (Linux, macOS, Windows) and architectures (Intel x86/x86-64, ARM64, WebAssembly, ARM), as well as many others, are supported. You can expect performance to be on a similar level to that of C++ or Java. Compared to interpreted Python code, the improvement can be huge.

Go is garbage collected, protecting against memory leaks. The collection has very low latency. In fact, you may never notice that the GC thread is there.

The normal libraries are stereo typically of high quality, with enhanced code using efficient algorithms. As an example, regular expressions are very efficient in Go with running time rectilinear in the size of the input. Regrettably, this is not correct for Java and Python. Build speeds, in complete terms, are currently fairly good. More notably, Go is designed to make compilation and dependency analysis easy, making it possible to create programming tools that goes with rising projects.

 

AWS

Installation Instructions For Ubuntu

Note: How to find PublicDNS in AWS

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Ubuntu instance on AWS Cloud

1) Download Putty.

2) Connect to the virtual machine using SSH key Refer this link:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Step 2) Other Information:

1.Default ports:

  • Linux Machines:  SSH Port – 22

2. To access Webmin interface for management please follow this link

Configure custom inbound and outbound rules using this link

Azure


Installation Instructions For Ubuntu

Installation Instructions For Ubuntu

Note: How to find PublicDNS in Azure

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Ubuntu instance on Azure Cloud

1) Download Putty.

2) Connect to the virtual machine using following SSH credentials:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine ( For example:  Azureuser)

Password: Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Other Information:

1.Default ports:

  • Linux Machines:  SSH Port – 22

2. To access Webmin interface for management please follow this link

Configure custom inbound and outbound rules using this link

Google

Installation Instructions For Ubuntu

Installation Instructions For Ubuntu

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Ubuntu instance on Google Cloud

1) Download Putty.

2) Connect to the virtual machine using SSH key

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Step 2) Other Information:

1.Default ports:

  • Linux Machines:  SSH Port – 22

2. To access Webmin interface for management please follow this link

Video

Ubuntu Installation

Golang on Cloud

Related Posts