페이지

2020년 6월 19일 금요일

What Goes into a Header File? What Goes Into a Non-Header File?

* Pretty much everyghing that has a "name" in C++ must be declared before you can use it. Many of these things must also be defined, but that can generally be done at a much later time.

* You declare a name by saying what kind of thing it is:

  const int MaxSize;                 //  declares a constant
  extern int v;                         // declares a variable
  void foo (int formalParam);     // declares a function(and a formal parameter)
  class Bar{...};                        // declares a class
  typedef Bar* BarPointer;        // declares a type name


* In most cases, once you have declared a name, you can write code that uses it. Furthermore, a program may declare the same thing any number of times, as long as it does so consistently. That's why a single header file can be included by several different non-header files that make up a program - header files contain only declarations.

* You define constants, variables, and functions as follows:

const int MaxSize = 1000;                        // defines a constant
int v;                                                   // defines a variable
void foo(int formalParam){++formalParam;} //defines a function

* A definition must be seen by the compiler once and only once in all the compilations that get linked together to form the final program. A definition is itself also a declaration (i.e., if you define something that hasn't been declared yet, that's OK. The definition will serve double duty as declaration and definition.).

* When a non-header file is compiled, we get an object-code file, usually ending in ".o". These are binary files that are "almost" executable - for some variables and function, instead of the actual address of that variable/function; they still have its name. This happens when the variable or function is declared but not defined in that non-header file ( after expansion of #includes by the pre-processor).

* That name will be assigned an address only when a file containing a definition of that name is compiled. And that address will only be recorded in the object code file corresponding to the non-header source file where the name was defined.

* The complete executable program is then produced by linking all the object code files together. The job of the linker is to find. for each name appearing in the object code, the address that was eventually assigned to that name, make the substitution, and produce a true binary executable in which all names have been replaced by addresses.

* Understanding this difference and how the entire compilation/build process works (Figure 7.1, "Building 1 program from many files") can help to explain some common but confusingly similar error messages:

If the compiler says that a function is undeclared, it means that you tried to use it before presenting its declaration, or forgot to declare it at all.

* The compiler never complains about definitions, because an apparently missing definition might just be in some other non-header file you are going to compile later. but when you try to produce the executable program by linking all the compiled object code files produced by the compiler, the linker may complain that a symbol is undefined (none of the compiled files provided a definition) or is multiply defined (you provided two definitions for one name, or somehow compiled the same definition into more than one object-code file).

* For example, if you forget a function body, the linker will eventually complain that the function is undefined. If you put a variable or function definition in a .h file and include that file from more than one place, the linker will complain that the name is multiply defined.

























Compiling and Executing Go Programs

* Now that you know how to create and edit files, you can generate new programs. The most commonly used languages in the CS Department at the moment are C++, C, and Java.

The most popular C++ and C compilers are g++ and gcc. 
The Structure of C++ and C Programs

* Although not really a Unix-specific topic, it's hard to discuss how to compile code under any operating system wityhout a basic understanding how programs are put together.

* The source code for a C++(or C) program is contained in a number of text files called source files. Very simple programs might be contained within a single source file, but as our programs grow larger and more complicated, programmers try to keep things manageable by splitting the code into multiple source files, no one of which should b terribly long.

* There are two dirrenrent kinds of source files: header files and not-header files. Header files are generally given names ending in ".h". Non-header files are generally given names ending in ".cpp" for C++ code and ".c" for C code.

* Header and non-header files are treated differently when we build programs. Each non-header file i compiled separately from the others (Figure 7.1, "Building 1 program from many files"). This helps keep the compilation times reasonable, particularly when we are fixing bugs in a program and may have changed only one or two non-header files. Only those changed files need to b recompiled.

* Header files are not compiled directly, Instead, header files are included into other source files via #include. In fact, when you invoke a C/C++ compiler, before the "real" compiler starts, it runs a pre-processor whose job is to handle the special instructions that begin with #. In the case of #include statements, the pre-processor simply grabs the relevant header file and sticks it content into the program right at the spot of the #include.


#include <iostream>
#incldue <string>

using namesapce std;
int main()
{
    string greeting = "Hello!";
    cout << greeting << endl;
    return 0;
}

* This can result in a dramatic increase in the amount of code that actually gets processed. The code shown here, for example, is pretty basic. But the #include statements bring in a entire library of I/O and string-related declarations from the C++ standard library. Here, for example, is the output of the pre-processor for one compiler. (If you look at the very end, you can recognize the main code for this program.)

* A header file can be #included from any number of other header and non-header files. That is, in fact, the whole point of having header files. Header files should contain declarations of things that need to be shared by multiple other source files. Non-header files should declare only things that do not need to be shared.

* As we go though all the compilation steps required to build a program, anything that appears in a non-header file will be processed exactly once by the compiler.
Anything that appears in a header file may be processed multiple times by the compiler.




















Go Programs

* A Go program can vary in length from 3 lines to millions of lines and it should be written into one or more text files with the extension ".go". For example, hello.Go.  You can use "vi" ", "vim" or any other text editor to write your Go program into a file.

Features Excluded Intentinally


* To keep the language simple and concise, the following features commonly available in other similar languages are omitted in Go:

1. Support for type inheritance
2. Support for method or operator overloading
3. Support for circular dependencies among packages
4. Support for pointer arithmetic
5. Support for assertions
6. Support for generic programming


Features of Go Programming

Binaries

* Go generates binaries for your applications with all the dependencies built-in. This removes the need for you to install runtimes that are necessary for running your application. This eases the task of deploying apoplications and providing necessary updates across thousands of ins tallations. With its support for multiple OS and processor architectures, this is a big win for the language.

Language Design

* The designers of the language made a conscious decision to keep the language simple and easy to understand. The entire specification is in a small number of pages and some interesting design decisions were made vis-a-vis Object-Oriented support in the language that keeps the features limited.

* Towards this, the language is opinionated and recommends an idiomatic way of achieving things. It prefers Composition over Inheritance and its Type System is elegant and allows for behavior to be added without tight coupling the components too much. In Go Language, "Do More with Less" is the mantra.

Powerful Standard Library

* Go comes with a powerful standard library, distributed as packages. This library caters to most components, libraries that developers have come to expect from 3rd party packages when it comes to other languages. A look at the Packages available in the standard library is good enough indication of the power available in them.


Package Management

* Go combines modern day developer workflow of working with Open Source projects and includes that in the way it manages external packages. Support is provided directly in the tooling to get external packages and publish your own packages in a set of easy commands.

Static Typing

* Go is a statically typed language and the compiler works hard to ensure that the code is not just able to compile correctly but other type conversions and compatibility are taken care of. This can avoid the problems that one faces in dynamically typed languages, where you discover the issues only when the code is executed.

Concurrency Support

* One area where the language shines is its first-class support for Concurrency in the language itself. If you have programming concurrency in other languages, you understand that it is quite complex to do so. Go Concurrency primitives via go routines and channels makes concurrent programming easy. Its ability to take advantage of multi-core processor architectures and efficient memory is one of the reasons while Go code is today running some of the most heavily used applications that are able to scale.

Testing Support

* Go Language brings Unit Testing right into the language itself. It provides a simple mechanism to write your unit tests in parallel with your code. The tooling also provides support to understand code coverage by your tests, benchmarking tests and writing example code that is used in generating your code documentation.

* Go has seen sighnificant adoption from large projects and due to its tooling, ecosystem and language design, programmers are steadily moving towards it, especially while building out infrastructure pieces. We expect that its popularity will continue to rise. Getting started with Go is straightforward and the Go Programming Language Home page has everything from installing the tool-chain to learning about Go.


















2020년 5월 10일 일요일

What is Kubernetes?

In 2017, Docker adoption was up 40%
amongst Datadog's very large customer base
source: "8 Surprising facts About Real Docker Adoption." Datadog, April 2017

The median number of containers running on a single host is aboput 10.
Source: "The 2017 Dockedr Usage Report." Sysdig, April 17, 2017

How do you manage all these containers running on a single host, and across your whole infrastructure?

Orchestrator Features 
* Provision hosts
* Instantiate containers on a host
* Restart failing containers
* Expose containers as services outside the cluster
* Scale the cluster up or down

Kubernetes(K8s)
* Definition: an open-source platform designed to automate deploying, scaling, and operating application containers
* Goal: to foster an ecosystem of components and tools that relieve the burden of running applications in public and private clouds 

Borg was the predecessor to Kubernetes.

Kubernetes is a platform to schedule and run containers on clusters of virtual machines. It runs on bare metal, virtual machines, private datacenter and public cloud.

No golden handcuffs when migrating to the cloud

Kubernetes and Docker
Kubernetes is a container platform

You can use Docker containers to develop and build applicastions, and then use Kubernetes to run these applications on your infrastructure.

Features Kubernetes
"Kubernetes is an open source project that enables software teams of all sizes, from a small startup to a Fortune 100 comapny, to automate deploying, scaling, and managing applications on a group or cluster of server machines..."
"These applications can include everything from internalfacing web applications like a content management system to marquee web properties like Gamil to big data processing."
- Joe Beda

Multi-Host
Container Scheduling
* Done by the kube-scheduler
* Assigns pods to nodes at runtime
* Checks resources, quality of service, policies, and user specifications before scheduling


Scalability and Availability
* K8s master can be deployed in a highly available configuration
* Multi-region deployments available

Scalability (v 1.8)
* Supports 5,000 node clusters
* 150,000 total pods
* Pods can be horizontally scaled via API

Flexibility and Modularization
* Plug-and-play architecture
* Extend architecture when needed
* Add-ons: network dirvers, service3 discovery, container runtime, visualization, and command

Registration
Seamless nodes register themselves with master

Service Discovery
Automatic detection of services and endpoints via DNS or environment variables.

Persistent Storage
* Much requested and important feature when working with containers
* Podc can use persistent volumes to store data
* Data retained across pod restarts and crashes




















 

2020년 5월 9일 토요일

What Is Containerization?

1. History of Containers


Container:
A collection of software processes unified by one namespace, with access to an operating system kernel that ist shares with other containers and little to no access between containers.


Dociker Instance
A runtime instance of a Docker image contains three things:
1. A Docker image
2. An execution environment
3. A standard set of instructions



Virtual Machine (VM)
* One or many applications
* The necessary binaries and libraries
* The entire guest operating system to interact with the applications

Containers
* Include the application and all of its dependencies
* Share the kernel with other containers
* Not tied to infrastructure only needs Docker Engine installed on the host
* Run as isolated processes in user space on the host OS

Container Benefits for Developers
Applicaton are
1. Portable
2. Packaged in a standard way

Deployment is 
1. Easy
2. Repeatable

Container Benefits for Developers
* Automated testing, packaging, and integrations
* Support newer microservice architectures
* Alleviate platform compatibility issues

Container Benefits for DevOps
* Reliable deployments: improve speed and frequency of releases
* Consistent application lifecycle: configure once and run multiple times

Container Benefits for DevOps

Consistent environments
* No more process differences between dev and production environments

Simple scaling
* Fast deployments ease the addition of workers and poermit workeload to grow and shrink for on-demand use cases


The DevOps team can isolate and debug issues at the container level.

Use of Containerized Apps on the Rise

Among 195 organizations surveyed in January 2017, organizations expect that their number of containerized applications will rise by 80% in the next tow years.

Containers: Real Adoption And Use Cases In 2017 (March 2017), Forrester Consulting Thought Leadership Paper Commissioned by Dell EMC, Intel, and RedHat

Containers and Microservices

Allow the Building of Pipelines

* Containers bring agility toi your code
* Help build a continuous integration and deployment pipeline
* Push an IT team to develop, test, and deploy applications faster