Dec 25, 2019

Dev OPS - Part 2

https://oracle-plsql10g.blogspot.com/2016/12/dev-ops.html

DevOps = Continuous Delivery + Operatability














UNDO & TEMP Tablespace

Oracle stores global temporary table  rows in the users temporary tablespace of the user, but you can change this to a "real" tablespace by using the tablespace clause of the create global temporary table syntax.

Prior to Oracle12c, Oracle transactions used UNDO for temporary tables (WITH Clause materializations, global temporary tables) within the standard UNDO tablespace.  Now, you can specify "alter session set temp_undo_enabled=true" to force the UNDO to be managed within the TEMP tablespace instead of within the UNDO tablespace

R & its Examples

The core of R is an interpreted computer language which allows branching and looping as well as modular programming using functions.
R was initially written by Ross Ihaka and Robert Gentleman at the Department of Statistics of the University of Auckland in Auckland, New Zealand.

Features of R

As stated earlier, R is a programming language and software environment for statistical analysis, graphics representation and reporting. The following are the important features of R −

R is a well-developed, simple and effective programming language which includes conditionals, loops, user defined recursive functions and input and output facilities.

R has an effective data handling and storage facility,
R provides a suite of operators for calculations on arrays, lists, vectors and matrices.
R provides a large, coherent and integrated collection of tools for data analysis.
R provides graphical facilities for data analysis and display either directly at the computer or printing at the papers.

As a conclusion, R is world’s most widely used statistics programming language.

It is the #1 choice of data scientists and supported by a vibrant and talented community of contributors.

Single comment is written using # in the beginning of the statement as follows −
R does not support multi-line comments but you can perform a trick which is something as follows −

if(FALSE) {"This is a demo for multi-line comments and it should be put inside either a single OR double quote" }

myString <- ello="" p="" world="">print ( myString)

Though above comments will be executed by R interpreter, they will not interfere with your actual program. You should put such comments inside, either single or double quote.

Generally, while doing programming in any programming language, you need to use various variables to store
various information. Variables are nothing but reserved memory locations to store values. This means that, when you create a variable you reserve some space in memory.

In contrast to other programming languages like C and java in R, the variables are not declared as some data type. The variables are assigned with R-Objects and the data type of the R-object becomes the data type of the variable.So R is called a dynamically typed language, which means that we can change a variable’s data type of the same variable again and again when using it in a program


 There are many types of R-objects. The frequently used ones are −


Vectors
Lists
Matrices
Arrays
Factors
Data Frames

The simplest of these objects is the vector object and there are six data types of these atomic vectors, also termed as six classes of vectors. The other R-Objects are built upon the atomic vectors.

Logical ,Numeric ,Integer ,Complex ,Character ,Raw

Vectors

When you want to create vector with more than one element, you should use c() function which means to combine the elements into a vector.

# Create a vector.
apple <- c="" green="" p="" red="" yellow="">print(apple)

# Get the class of the vector.
print(class(apple))

A list is an R-object which can contain many different types of elements inside it like vectors, functions and even another list inside it.

# Create a list.
list1 <- c="" list="" p="" sin="">
# Print the list.
print(list1)

A matrix is a two-dimensional rectangular data set. It can be created using a vector input to the matrix function.
# Create a matrix.
M = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol = 3, byrow = TRUE)
print(M)

While matrices are confined to two dimensions, arrays can be of any number of dimensions. The array function takes a dim attribute which creates the required number of dimension.
# Create an array.
a <- array="" c="" dim="c(3,3,2))</p" green="" yellow="">print(a)

Factors are the r-objects which are created using a vector. It stores the vector along with the distinct values of the elements in the vector as labels. The labels are always character irrespective of whether it is numeric or character or Boolean etc. in the input vector. They are useful in statistical modeling.

Factors are created using the factor() function.The nlevels functions gives the count of levels.
# Create a vector.
apple_colors <- c="" green="" p="" red="" yellow="">
# Create a factor object.
factor_apple <- apple_colors="" factor="" p="">
# Print the factor.
print(factor_apple)
print(nlevels(factor_apple))

Data Frames

Data frames are tabular data objects. Unlike a matrix in data frame each column can contain different modes of data. The first column can be numeric while the second column can be character and third column can be logical. It is a list of vectors of equal length.

Data Frames are created using the data.frame() function.
# Create the data frame.
BMI <- span="" style="white-space: pre;">
data.frame(   gender = c("Male", "Male","Female"),
   height = c(152, 171.5, 165),
   weight = c(81,93, 78),
   Age = c(42,38,26)
) print(BMI)

The values of the variables can be printed using print() or cat()function. The cat() function combines multiple items into a continuous print output.

# Assignment using equal operator.
var.1 = c(0,1,2,3)         

# Assignment using leftward operator.
var.2 <- c="" learn="" nbsp="" p="">
# Assignment using rightward operator. 
c(TRUE,1) -> var.3         

print(var.1)
cat ("var.1 is ", var.1 ,"\n")
cat ("var.2 is ", var.2 ,"\n")
cat ("var.3 is ", var.3 ,"\n")

Finding Variables

To know all the variables currently available in the workspace we use the ls() function. Also the ls() function can use patterns to match the variable names.

print(ls())

Deleting Variables

Variables can be deleted by using the rm() function. Below we delete the variable var.3. On printing the value of the variable error is thrown.
rm(var.3)
print(var.3)

All the variables can be deleted by using the rm() and ls() function together.
rm(list = ls())
print(ls())

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. R language is rich in built-in operators and provides following types of operators.

Types of Operators

We have the following types of operators in R programming −

Arithmetic Operators +  −  *  /  %%  %/%
Relational Operators  >  <  ==   <=   >=   !=
Logical Operators &  |  !
Assignment Operators
Miscellaneous Operators

Built-in Function

Simple examples of in-built functions are seq(), mean(), max(), sum(x) and paste(...) etc
# Create a sequence of numbers from 32 to 44.
print(seq(32,44))

# Find mean of numbers from 25 to 82.
print(mean(25:82))

# Find sum of numbers frm 41 to 68.
print(sum(41:68))

# Create a function to print squares of numbers in sequence.
new.function <- 1:a="" a="" b="" for="" function="" i="" in="" nbsp="" p="" print="">
# Call the function new.function supplying 6 as an argument.
new.function(6)


Redis DB & its use case

Redis is used in thousands of production deploys,

Redis has a proven record of stability. If it runs low on memory, it just evicts older records faster. Additionally, with ElastiCache we can place replica nodes in multiple availability zones and use a single endpoint that will seamlessly switch to a replica if a primary goes down.

2.Performant: Redis runs in memory and we configure it without disk flushes. Its read and write complexity is O(1), so it performs the same regardless of data size.

3.Scalable: Because our sessions expire, we simply set an expiry on our records in Redis and our memory usage reaches an equilibrium, currently at 5GB. If we need to scale further, we can replicate to a node with more memory and then promote it to primary.

Redis is key-value store that stores all its data in RAM.

Redis implements replication using a primary and replica where

•Writes go to the primary. Reads can go to either the primary or replica.
•Writes are replicated to the replicas by asynchronous/non-blocking replication which means that a write is “committed” without waiting to be replicated

•The primary can have multiple replicas, which in turn can have other replicas connected to them

Amazon ElastiCache is a service that provides an easy way to build a highly resilient Redis setup with primary/secondary in multiple zones with automated failover.

Use-Case 

After we decided upon our technology, we needed to test and implement it in production without downtime. Building the system and then switching over to it all at once is a recipe for disaster.

we rely heavily on “dark launching”, checking new code into production and then turning on and off execution of that code through a management console for a certain percentage of requests or users.

In the first stage, we wanted to test reads and writes to Redis but still rely on the old setup. Starting at 1% of requests and ramping up to 100%, we mirrored traffic on both MySQL + Memcached and Redis. On every read to MySQL + Memcached we issued the same read request to Redis, and the same for writes. During this testing we gained a lot of knowledge about how the system performed on production traffic.