Oracle笔记(2)——Oracle相关的环境变量

安装和使用Oracle时相关的环境变量:

(1)ORACLE_BASE
安装Oracle时的根目录,默认值为/u01/app/oracle

(2)ORACLE_HOME
安装特定版本Oracle时的目录,例如$ORACLE_BASE/product/11.2.0/dbhome_1

(3)ORACLE_SID
标明数据库的System Identifier(SID)SID用来代表某个数据库实例(instance),用来同其它instance相区分。

参考资料:
Administering Oracle Database
http://www.orafaq.com/wiki/ORACLE_SID
Oracle Database – Environment Variables / Registry Values

 

Sysdig笔记(3)——chisel

Sysdig中的chisel是用Lua语言编写的脚本,用来分析和处理sysdig产生的eventSysidg会在下列目录中查找chisel., ./chisels, ~/chisels和/usr/share/sysdig/chisels

列出sysdig所有的chisel

# sysdig -cl

Category: Application
---------------------
httplog         HTTP requests log
httptop         Top HTTP requests
memcachelog     memcached requests log

Category: CPU Usage
-------------------
spectrogram     Visualize OS latency in real time.
......

如果想查看关于某个chisel的详细信息,可以使用-i选项:

# sysdig -itopfiles_bytes

Category: I/O
-------------
topfiles_bytes  Top files by R+W bytes

Shows the top files in terms of disk usage. This chisel is compatable with cont
ainers using the sysdig -pc or -pcontainer argument, otherwise no container inf
ormation will be shown.
Args:
(None)

执行chisel使用-c选项:

# sysdig -c topfiles_bytes
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
144B                /dev/ptmx
Bytes               Filename
--------------------------------------------------------------------------------
165B                /dev/ptmx

也可以为chisel指定参数:

# sysdig -c topfiles_bytes "not fd.name contains /dev"
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
7.47KB              /proc/cpuinfo
1024B               /proc/meminfo

参考资料:

Sysdig Quick Reference Guide

Chisels User Guide

Haskell笔记 (17)—— Value和type

Because Haskell is a purely functional language, all computations are done via the evaluation of expressions (syntactic terms) to yield values (abstract entities that we regard as answers). Every value has an associated type. (Intuitively, we can think of types as sets of values.) Examples of expressions include atomic values such as the integer 5, the character ‘a’, and the function \x -> x+1, as well as structured values such as the list [1,2,3] and the pair (‘b’,4).

Just as expressions denote values, type expressions are syntactic terms that denote type values (or just types). Examples of type expressions include the atomic types Integer (infinite-precision integers), Char (characters), Integer->Integer (functions mapping Integer to Integer), as well as the structured types [Integer] (homogeneous lists of integers) and (Char,Integer) (character, integer pairs).

All Haskell values are “first-class”—they may be passed as arguments to functions, returned as results, placed in data structures, etc. Haskell types, on the other hand, are not first-class. Types in a sense describe values, and the association of a value with its type is called a typing. Using the examples of values and types above, we write typings as follows:

                      5  :: Integer
                     'a' :: Char
                     inc :: Integer -> Integer
                 [1,2,3] :: [Integer]
                 ('b',4) :: (Char,Integer)

The “::” can be read “has type.”

Haskell是一门纯函数式编程语言,所有的计算都是通过对表达式的求值完成的。每个值(value)都有一个相关的类型(type),也可以把类型看做是值的集合。在Haskell中,所有的值都是first-class,而类型却不是。类型和值的集合称之为typing

5  :: Integer

 

Haskell笔记 (16)—— Currying

Currying定义如下:

Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.

Haskell中所有函数都可以认为是curried,即函数只包含一个参数。在Haskell类型表示中,->是右相关的,因此f :: a -> b -> c实际上也是f :: a -> ( b -> c ),所以f x y(f x) y

参考资料:
Currying

下面参考自Curried functions

Every function in Haskell officially only takes one parameter. So how is it possible that we defined and used several functions that take more than one parameter so far? Well, it’s a clever trick! All the functions that accepted several parameters so far have been curried functions.

Putting a space between two things is simply function application. The space is sort of like an operator and it has the highest precedence.

So how is that beneficial to us? Simply speaking, if we call a function with too few parameters, we get back a partially applied function, meaning a function that takes as many parameters as we left out. Using partial application (calling functions with too few parameters, if you will) is a neat way to create functions on the fly so we can pass them to another function or to seed them with some data.

关于curry infix function(需要加括号):

Infix functions can also be partially applied by using sections. To section an infix function, simply surround it with parentheses and only supply a parameter on one side. That creates a function that takes one parameter and then applies it to the side that’s missing an operand. An insultingly trivial function:

divideByTen :: (Floating a) => a -> a  
divideByTen = (/10) 

The only special thing about sections is using -. From the definition of sections, (-4) would result in a function that takes a number and subtracts 4 from it. However, for convenience, (-4) means minus four. So if you want to make a function that subtracts 4 from the number it gets as a parameter, partially apply the subtract function like so: (subtract 4).

 

如何理解“load average”?

*nix系统中,执行topuptime命令可以显示当前系统的load average(分别是过去1515分钟的load平均值):

# uptime
 14:43:37 up 22 days,  1:47,  5 users,  load average: 0.00, 0.01, 0.05

load指的是正在使用和等待使用CPUprocess的数量和。因此,在单核系统上,load average这个值低于1.00表示系统还很空闲,1.00表示系统已经达到100%利用率了,高于1.00就需要引起注意了。

此外,100%利用率和系统处理器数目有关,单核系统的值是1.00,双核系统值就是2.00了,以此类推。因此在多处理器系统上,有可能load average的值很高,可是系统CPU实际上还很空闲。

P.S.:得到CPU数目的方法:

# grep 'model name' /proc/cpuinfo | wc -l
8

参考资料:
WHAT ABOUT MULTI-PROCESSORS? MY LOAD SAYS 3.00, BUT THINGS ARE RUNNING FINE!

What’s the difference between load average and CPU load?

Examining Load Average

load average video

 

从函数式编程角度思考awk

昨天读到这篇文章:Awk, Unix, and functional programming,作者从函数式编程角度考虑awk,把awk总结为一个函数式程序:

Awk(action) =
    for each file
      for each input line
        for each pattern
          if pattern matches input line
            do action(fields)

即把awk程序看做一个函数,action作为awk的参数。对符合pattern的输入行,调用action处理这一行的每个field。上面这段伪代码可以帮助我更好地理解awk

 

Haskell笔记 (15)—— Type annotation

当需要显示地指定表达式类型时,可以使用type annotaion,即在表达式后面加上::和需要指定的类型。举例如下:

> :type 1 :: Int
1 :: Int :: Int

可以看到1被强制指定为Int类型。Type annotation也可以用来获得Int等类型的边界值:

> minBound :: Int
-9223372036854775808
> maxBound :: Int
9223372036854775807

参考资料:
Lecture Notes on Haskell Programming

 

Haskell笔记 (14)—— List comprehension

在数学中,comprehension可以表示为从一个集合生成另一个集合:

{x²  |  x ∈ {1...5}}

Haskell中,list comprehension可以表示从一个list生成另外一个list

> [x^2 | x <- [1 .. 10], even x]
[4,16,36,64,100]

list comprehension可以包含两部分:x <- [1 .. 10]generator,表明x的值从哪里获得;even xguard,相当于限制哪些x的值可以用于生成新的listGeneratorguard都可以有多个,用,分开:

> [x * y | x <- [1 .. 10], y <- [1 .. 10], even x, odd y]
[2,6,10,14,18,4,12,20,28,36,6,18,30,42,54,8,24,40,56,72,10,30,50,70,90]

需要注意的是,改变generator的顺序会改变最后生成list的顺序。多个generator像嵌套循环,位置靠后的是里层循环,位置靠前的是外层循环。举例如下:

> [(x, y) | x <- [1, 2, 3], y <- [4, 5]]
[(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
> [(x, y) | y <- [4, 5], x <- [1, 2, 3]]
[(1,4),(2,4),(3,4),(1,5),(2,5),(3,5)]

参考资料:
List Comprehensions

 

SmartOS上使用pkgin安装软件

我使用的SmartOS是安装在Vmware上的虚拟机,网络模式是NAT。装好的SmartOS缺少很多常用软件,需要自行安装:

(1)由于我的网络使用了proxy,所以需要配置一下:

export http_proxy="http://web-proxy.xxxxxx.com:8080/"
export https_proxy="https://web-proxy.xxxxxx.com:8080/"

(2)安装pkgin,我使用的是root用户:

# cd /
# curl -k http://pkgsrc.joyent.com/packages/SmartOS/bootstrap/bootstrap-2015Q4-x86_64.tar.gz | gzcat | tar -xf -
# pkg_admin rebuild
# pkgin -y up

(3)接下来就可以安装软件了,以gcc为例。首先查找gcc package

# pkgin se gcc
......
gcc49-4.9.3          The GNU Compiler Collection (GCC) - 4.9 Release Series
......

安装gcc

# pkgin in gcc49-4.9.3

安装好后就可以使用了:

# gcc
gcc: fatal error: no input files
compilation terminated.

参考资料:
Installing pkgin
Working with packages