report haiyong wang. outline a brief introduction to chef a brief introduction to ruby latching vs...

42
Report Haiyong Wang

Upload: margaretmargaret-logan

Post on 20-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Report

Haiyong Wang

Page 2: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Outline

• A brief introduction to Chef• A brief introduction to Ruby• Latching VS Locking

Page 3: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

A brief Introduction to Chef

Haiyong Wang

Page 4: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking
Page 5: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Outline

• What is chef• Architecture and installing• Using chef

Page 6: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

What is Chef

With Chef, you write abstract definitions as source code to describe how you want each part of your infrastructure to be built, and then apply those descriptions to individual servers.

Page 7: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Chef Provides

• Provisioning– Kickstart Jumpstart

• Configuration Management– Recipes , knife, cookbook

• Systems Integration

Page 8: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Chef Provides

Page 9: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Different Flavors of Chef

• Chef Solo• Chef Client and Chef Server• Hosted Chef

Page 10: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Chef Client and Chef Server

Page 13: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Installing

• Important files– Validation.pem– client.pem– knife.rb– Client.rb

Page 14: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Using chef

• Important concepts– Git– Cookbook– Recipe– Run_list

Page 15: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Using chef

cookbook Recipes

configure

bootstrap

Page 16: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Using Chef

• Useful links– Cookbook fast start• http://wiki.opscode.com/display/chef/Cookbook+Fast+

Start+Guide

– Github cookbook• https://github.com/opscode-cookbooks• https://github.com/infochimps-cookbooks

– Cookbook community• http://community.opscode.com/

Page 17: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Using Chef

• Hbase

Page 18: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Question ?

Page 19: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

A brief introduction to Ruby

Page 20: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Check the syntax

• ruby –c

• rake test

Page 21: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Assignment#assigning a local variable#no type declaration#no semicolonx = 1x, y, z = “100”, 200, 300# global variable$amout = 1#const variableName = “Floydene Wallup”name = “Floydene Wallup”

Page 22: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Basic Arithmetic

5/2 #=> 25/2.0 #=> 2.5(1+2)* 3 #=> 9

irb(main):001:0>3+4 #=> 7irb(main):002:0> 7-3 #=>4irb(main):005:0>3**4 #=> 81irb(main):007:0> x= 12 #=> 12irb(main):008:0> x+=1 irb(main):012:0> Math.sqrt(16) #=> 4

Page 23: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

strings'single quoted' # => "single quoted" "double quoted" # => "double quoted" 'It\'s alive' # => "It's alive!" "1 + 2 = 5" # => "1 + 2 = 5"

th = "Hello world“th[0..5] #=>Helloth[-5..-1] #=>world

Page 24: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Embedded

x = "Bob""Hi, #{x}" # => "Hi, Bob"'Hello, #{x}' # => "Hello, #{x}"

Page 25: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Bool variables

true # => true false # => false nil # => nil !true # => false !false # => true !nil # => true !!true # => true !!false # => false !!nil # => false!!0 # => true

Page 26: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Arrays

x = ["a", "b", "c"]# => ["a", "b", "c"] x[0] # => "a" (zero is the first index) x.first # => "a" x.last # => "c" x + ["d"] # => ["a", "b", "c", "d"]x # => ["a", "b", "c"] x = x + ["d"] # => ["a", "b", "c", "d"] x # => ["a", "b", "c", "d"]

Page 27: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Hash

# => { "first_name => "Bob", "last_name" => "Jones" }h = { "first_name" => "Bob", "last_name" => "Jones"}

h.keys # => ["first_name", "last_name"] h["first_name"] # => "Bob" h["last_name"] # => "Jones" h["age"] = 23h.keys # => ["first_name", "age", "last_name"] h.values # => ["Jones", "Bob", 23]

Page 28: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

perl-style regular expressions

"I believe" =~ /I/ # => 0"I believe" =~ /lie/ # => 4"I am human" =~ /bacon/ # => nil"I am human" !~ /bacon/ # => true/give me a ([0-9]+)/ =~ "give me a 7" # => 0

Page 29: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Conditional statement

if false # this won't happen else if nil # this won't either else # code here will runend

x = "dog"case x when "fish" # this won't happen when "dog", "cat", "monkey" # this will run else # the else is an optional catch-all end

Page 30: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Method

def do_something_useless( first, second) puts "You gave me #{first} and #{second}"

end

do_something_useless( "apple", "banana") # => "You gave me apple and banana"

do_something_useless 1, 2# => "You gave me 1 and 2"

Page 31: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Function of the following code?

n=120 primes = Array.new for i in 0..n-2

primes[i] = i+2 end index = 0 while primes[index]**2 <= primes.last

prime = primes[index] primes = primes.select { |x| x == prime || x%prime != 0 } index += 1

end p primes

Page 32: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Question ?

Page 33: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Page 34: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Purpose

– exclusive access to memory structures

Locking• Purpose

– share the same resource if compatible

– enforce exclusive access if incompatible.

Page 35: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Jurisdiction

– temporary memory objects– B-Tree index

Locking• Jurisdiction

– database objects – tables, data blocks

Page 36: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Acquisition

– willing-to-wait – no-wait

Locking• Acquisition

– Null– row share– row exclusive– Share– share row exclusive– exclusive

Page 37: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Scope

– instance level– Information kept in memory– visible to the local instance

Locking• Scope

– database-level– Information kept in database– visible to all instances

accessing the database

Page 38: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Complexity

– Lightweight– Simple instructions– port specific

Locking• Complexity

– Heavyweight– series of instructions with

context switches

Page 39: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Duration

– briefly – microseconds

Locking• Duration

– an extended period of time– transactional duration

Page 40: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Queue

– not queued

Locking• Queue

– queued

Page 41: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Locking and Latching

Latching• Deadlock

– No deadlocks

Locking• Deadlock

– deadlocks

Page 42: Report Haiyong Wang. Outline A brief introduction to Chef A brief introduction to Ruby Latching VS Locking

Thank you