죄표계 (R)eference 2008. 11. 6. 11:09
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. 개요

공간상의 한 물체 또는 한점의 위치는 일반적으로 좌표로써 표시된다. 위치란 어느 좌표계에 있어서 다른 점들과 어떤 기하학적인 상관관계를 갖는가를 의미하는 것으로, 일반적으로 그 좌표계의 특정점 또는 특정선으로부터의 길이와 방향을 매개로 하여 표현한다. 이때 어느 좌표계의 기준이 되는 고유한 한 점을 원점(origin), 매개가 되는 실수(어떤 길이, 또는 방향 등)을 좌표(Coordinate)라 한다.

2. 좌표계의 종류

1) 1차원 좌표계

1차원좌표는 주로 직선과 같은 1차원선형에 있어서 점의 위치를 표시하는데 쓰인다. 예를 들면, 직선상에 등속운동하는 물체를 생각할 때 어느 시점에서 이 물체의 위치는 기준점으로부터의 거리로 표시되며 이것은 시간과 속도의 함소로 나타냇 수 있을 것이다.
직선상의 점의 위치를 표시하려고 할 때 직선상에 기준이 되는 점을 Origin으로 잠고 양·음의 방향을 결정한 다음, 적당한 단위의 길이를 1로 하면 원점에서 어느 점까지의 거리는 하나의 수치로 나타낼 수 있으며 한 점의 위치는 하나의 실수와 대응한다. 이때 이 실수를 이점의 좌표라 한다.
아래 그림에서 P1 및 P2의 좌표는 x₁ =vt₁, x₂ =vt₂이며 P₁P₂의 길이는 x₂-x₁ =v(t₂ - t₁)이 된다. 이 값은 원점의 위치를 바꾸어도 변하지 않는다.

<1차원좌표>

 

2) 2차원 좌표계

a. Cartesian Coordinate

평면상의 1점의 위치를 표시하는데 있서 가장 대표적인 좌표계이다. 평면위에 한 점 O를 원점으로 정하고, O를 지나고 서로 직교하는 두 수직직선 XX´, YY´를 좌표축으로 삼는다. 평면상의 한 점 P위의 위치는 P를 지나며 X, Y축에 평행한 뒤 직선이 X, Y축과 만나는 P´ 및 P˝의 좌표축상 선분OP´ = x, 선분 OP˝ = y로 나타낼 수 있다. 측 평면상 한점 P의 위치는 두 개의 실수의 순서쌍(x, y)에 대응하며, 역으로 순서쌍(x,y)가 주어지면 두 좌표축으로부터 P의 위치가 결정된다.

<평면직교좌표>

b.Plane Oblique Coordinate

평면상 1점의 위치를 표시하기 위해서 임의의 각도로 경사되어 교차하는 두개의 수치직선을 좌표축으로 도입한 것으로 윗 그림의 오른쪽과 같이 평면상에서 교차하는 두 개의 수직직선을 각각 X, Y좌표축으로 잡고 그 교점 O를 원점으로 한다.

<평면사교좌표>

c.Plane Polar Coordinate

2차원극 좌표는 평면상 한점과 원점을 연결한 선분의 길이와 원점을 지나는 기준선과 그 선분이 이루는 각으로 표현되는 좌표이다.
극각 θ는 수학적 좌표계에서는 반시계방향으로 +로 하지만, 일반측량에서는 방위각 등과 같이 통상 시계방향을 +로 한다.
θ : Polar angle
O : pole
OX : Initial line or Polar axis
Cartesian Coordinate(x,y)와 Plane Polar Coordinate(r, θ)의 관계는 다음과 같다.
r=Γx² + y², θ=tan-¹(y/x)
x = r cos θ, y =r sinθ

<Plane Polar Coordinate>

3) 3차원 좌표계

a. Three-Dimensional Cartesian Coordinate

3차원 직교좌표는 공간의 위치를 나타내는데 가장 기본적으로 사용되는 좌표계로서 평면직교좌표계를 확장한 것으로, 서로 직교하는 세 축 OX, OY, OZ로 이루어진다. 공간에서 P(x,,y,z)의 3차원 직교좌표는 P를 지나며 각 축에 대해 수직을 이루는 평면들이 지나는 좌표축으로부터 읽을 수 있다.

OP의 길이 ρ는 세 좌표로 부터 다음 식으로 계산된다.
ρ = Γx²+y²+ z²
또 OP가 X, Y, Z축과 이루는 각을 α,β,γ 일때
cos²α + cos²β + cos²γ =  x²/ρ² + y²/ρ² + z²/ρ² =1

<Three-Dimensional Cartesian Coordinate>

 

c.Three-Dimensional Oblique Coordinate)

공간에 한 점 O를 원점으로 정하고, O를 지나며 서로 직교하지 않는 세 평면상에 O를 지나는 세 개의 수치직선 XOX´, YOY´, ZOZ´를 좌표축으로 잡는다. OX, OY, OZ를 양의 반직선으로 하는 좌표계를 도입하면 공간상 한 점 P에 대하여 세 개의 실수의 순서쌍이 대응된다. 즉 점 P를 지나며 세 걔의 기준평면 YOZ, XOZ, XOY에 평행한 세 평면이 세 좌표축 XX´,YY´,ZZ´과 만나서 점을 각각 L, M, N이라 하면 각 좌표축상의 길이는 선분OL =x , 선분 OM=y, 선분ON=z로써 점 위치를 좌표(x,y,z)로 지정할 수 있다.

<Three-Dimensional Oblique Coordinate>

c.Cylindrical Coordinate

공간에서 점의 위치를 표시하는데 원주좌표가 종종 편리하게 쓰이고 있으며, 평면 z=0 위의 (x,y) 대신 극좌표(Υ,θ)를 사용한다. 공간에서 O점을 원점으로 하는 직교좌표를 잡고 공간의 점 P(x,y,z)에서 X,Y 평면엣 수선 PP´를 내려서 OP´ =  Υ, ∠XOP = θ , PP = z라 하여 P점을 (Υ,θ,z )로 표현한다.

<Cylindrical Coordinate>

c.Spherical Coordinate

이 좌표계에서는 어떤 점의 위치를 하나의 길이와 두개의 각으로 나타낸다. 원점을 중심으로 대칭일 때 유용하다. 공간에서 O점을 직교좌 표축을 잡고 공간의 점 P(x,y,z)에 대하여 OP = ρ ∠ZOP = φ라고 하고, XY평면에 수선 PP´를 내려서 ∠XOP´ = θ라 하여 점 P를 (ρ, θ, φ)로 표현한다.

<Spherical Coordinate>

 

4) 지구좌표계

a. Geographic Coordinate

지구상 절대적 위치를 표시하는데 일반적으로 가장 널리 쓰이는 좌표계이다. 3차원구면 좌표계에서 구의 반경 ρ와 두개의 편각 θ,Φ로 구성되는 세 개의 실수(ρ,θ,Φ)가 대응하여야 하지만 통상 지구좌표계에서는 경도 λ와 위도 φ에 의한 좌표(λ,φ)로 수평위치를 나타낸다. 따라서 3차원 위치를 표시하려면 타원체면으로부터 높이, 또는 표고를 도입할 필요가 있다.  지구 타원체를 동서방향의 위도선과 남북방향의경도선을 도, 분, 초로 표시하며 투영법의 종류에 관계없이 임의의 위치점을 표현할 수 있다. 적도선을 0도 기준으로 하여 남북으로 각각 90도씩 적도에 평행하게 그은 선을 위도선이라 하며 적도를 중심으로 북쪽으로는 북위, 남쪽으로는 남위라고 한다. 또한 경도선은 일명 자오선이라고도 하는데 영국의 그리니치 천문대를 통과하는 본초자오선을 0도 기준으로 하여 동쪽으로 180도까지를 180등분한 선을 동경이라고 한다. 위도는 어느 지점의 연직선(또는 타원체의 법선)이 적도면과 이루는 각으로 정의할 수 있는데, 연직선과 타원체의 법선은 통산 일치하지 않고, 또 정희하는 방법에 따라 측지위도, 천문위도, 지심위도, 화성위도 등으로 구분한다.

< 경위도좌표>

 < 위도별 경도의 길이 >

위도 (° )

위도 1도의 길이(km)

경도 1도의 길이 (km)

0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90

110.569
110.578
110.603
110.644
110.701
110.770
110.850
110.941
111.034
111.132
111.230
111.327
111.415
111.497
111.567
111.625
111.666
111.692
111.700

111.322
110.902
109.643
117.553
114.650
100.953
96.490
91.290
85.397
78.850
71.700
63.997
55.803
47.178
38.188
28.904
19.394
9.735
0.000

b. TM(Transverse Mercator)

TM 좌표는 임의의 지역에 대한 기준 지점을 좌표 원점으로 정하고 원점을 중심으로 TM투영한 평면상에서 원점을 지나는 자오선을 X축, 동서방향의 위도선을 Y축으로 하여 각 지점의 위치를 m단위의 평면 직각좌표계로 표시한다. 이것은 수학에서의 좌표축과는 다르다
우리나라에서는 TM 좌표 또는 평면 직각좌표계에서의 좌표 기준점으로 서부 원점(125° E, 38° N), 중부 원점(127° E, 38° N), 동부 원점(129° E, 38° N)의 3개 원점을 사용한다. 여기서 X축은 북쪽 방향이 양의 값을 나타내고, Y축은 동쪽 방향이 양의 값을 나타난다.
우리나라의 평면직각좌표의 원점은 통일원점 3개, 기타원점 11개로 구성되어 있다. 통일원점은 북위 38도, 동경 125도, 127도, 129도로 3개원점이 위치하고 있고, 각각의 평면직교좌표계에서 모든 지역의 좌표가 양수가 되게 하기 위해 종축(X축)에는 500,000m(단, 제주도는 550,000m), 횡축(Y축)에는 200,000m를 더합니다. 기타원점은 구소삼각측량 시행지역에 위치하는 것으로 경기도 지역과 경북지역에 있으며 그 현황은 다음과 같다

< 우리나라 원점계 >

구분 원점명 경도 위도
통일원점 서부
중부
동부
125°
127
°
129
°
38°
38
°
38
°
기타원점 망 
계 양
조 본
가 리
동 경
고 초
 율 곡 
현 창
구 암
금 산
소 라
126°  22´ 24.596˝
126
°  42´ 49.658˝
127
°  14´ 07.397˝
126
°  51´ 59.430˝
126
°  51´ 32.845˝
127
°  14´ 41.585˝
128
°  57´ 10.915˝
128
°  46´ 03.947˝
128
°  35´ 46.186˝
128
°  17´ 26.070˝
128
°  43´ 36.841˝
37°  43´ 07.060˝
37 
° 33´ 01.126˝
37
°  26´ 35.262˝
37
°  25´ 30.532˝
37
°  11´ 52.885˝
37
°  09´ 30.530˝
35
°  57´ 21.322˝
35
°  51´ 46.967˝
35
°  51´ 30.878˝
35
°  43´ 46.532˝
35
°  39´ 58.199˝

c. UTM(Universal Transverse Mercator)

UTM 투영법에 의하여 표현되는 좌표계로서 적도를 횡측, 자오선을 종축으로 한다. 이 방법은 지구를 회전타원체로 보고 지구전체를 경도 6°씩 60개 구역(종대, column)으로 나누고 그 각 종대의 중앙자오선과 적도의 교점을 원점으로 하여 원통도법인 횡 Mercator(TM) 투영법으로 등각투영한다. 각 종대는 180°W 자오선에서 동쪽으로 6°간격으로 1부터 60까지 번호를 붙인다. 종대에서 위도는 남. 북에 80까지만 포함시키며 8°간격으로 20구역(row)으로 나누어 C(80°S ~ 72°S)에서 X(72°N ~ 80°N)까지 (단, I와 O는 제외) 알파벳 문자로 표시한다. 따라서 종대 및 횡대는 결국 경도 6° X 8°의 직각형 구역으로 구분된다.
UTM좌표에서 거리좌표는 m 단위로 표시하며 종좌표에서는 N을, 횡좌표에서는 E를 붙인다. 각 종대마다 좌표원점의 값을 북반구에서 횡좌표 500,000mE, 종좌표 0mN(남반구에서는 10,00,000N)으로 주면 북반구에서 종좌표는 적도에서 0mN, 80°N에서 10,000,000mN이고, 남반구에서는 80°S에서 적도까지의 거리는 10,000,000m로 나타난다. 80°N과 80°S간 전 지역의 지도는 UTM좌표로 표시하며 80°N이북과 80°S이남의 양극지역의 전 지역의 지도는 국제극심입체좌표(UPS)로 표시함으로써 전 세계를 일관된 좌표계로 나타낼 수 있다.
지도 1장의 도곽을 구성하는 경위선을 서로 직교하는 곡선으로 나타나며 1/50,000 이상에서는 실용상 직선으로 보아도 무방하다. Gauss-Kruger 투영에서는 중앙경선의 길이가 지구상과 같지만(선확대율 Kο =1) UTM투영에서는 Kο=0.9996으로 축호한 지역의 오차는 ±4/10,000 ~ 6/10,000정도이다.
처음 UTM좌표는 세계 제2차세계대전 말기 연합군의 군용거리좌표로 고안된 것으로 주로 군용좌표로 사용되어 왔으나 지도제작과 사용상 편리함 점이 많으므로 근래에는 세계적으로 대축척 지도좌표로 널리 사용되어 왔다.

우리나라의 경우 UTM좌표 구역은 그림 II-9에서와 같이 동서 방향으로 51, 52구역 및 남북방향으로, S, T 구역에 속한다. 51구역의 경우 중앙 자오선은 123° E 이며 52구역은 129° E가 된다. 또한 32° N에서 40° N 구역은 S로 표기하며 40° N에서 48° N 까지는T구역으로 표시한다. UTM 좌표를 표기하는 예로 경위도좌표 37° 43’ 36’N, 127° 13’ 55’E 의 경우WGS84 타원체기준으로 UTM좌표로 표기하면 52 S 구역의 (4,176,960mN , 344,189mE)로 나타낼 수 있다.

< 그림 UTM 좌표 >

d. UPS(Universal Polar Stereographic)

UPS좌표는 위도 80°이상의 양극 지역의 좌표를 표시하는데 사용한다. 이 좌표계는 양극을 원점으로 하는 평면직교좌표계를 사용하며, 거리좌표는 m단위로 나타낸다. 좌표의 종축은 경도 0° 및 180°인 자오선이고 횡축은 90° W및 90° E인 자오선이다. 원점의 좌표값은 횡좌표 2,000.000mE, 종좌표 2,000,000mN이며 도북은 북극을 지나는 180° 자오선(남극에서는 0° 자오선)과 일치한다. 
가로선의 끝좌표는 북극의 경우 경도 0도 부근의 최하단 횡선이 1,000,000mN, 원점이 2,000,000mN, 경도 180° 부근의 최단 횡선이 3,000,000mN이다. 세로선은 90° W부근이 1,000,000Mn, 원점이 2,000,000mN, 90° E부근이 3,000,000mN이다. 남극의 경우는 경향이 반대에 해당된다. 북극 지역은 84° N까지를 UPS좌표로 표현할 수 있으며 남극 지역은 80° 까지 표현할 수 있다.

<UPS좌표방안>

 


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Linux Shell Scripting Tutorial v1.05r3
A Beginner's handbook

Copyright © 1999-2002 by Vivek G. Gite <vivek@nixcraft.com>

nixCraft Logo :: Next generation *nix services
(Formally know as vivek-tech.com)

Linux Shell Scripting Tutorial - A Beginner's handbook

Table of Contents

Chapter 1: Quick Introduction to Linux
What Linux is?
Who developed the Linux?
How to get Linux?
How to Install Linux
Where I can use Linux?
What Kernel Is?
What is Linux Shell?
How to use Shell
What is Shell Script ?
Why to Write Shell Script ?
More on Shell...
Chapter 2: Getting started with Shell Programming
How to write shell script
Variables in shell
How to define User defined variables (UDV)
Rules for Naming variable name (Both UDV and System Variable)
How to print or access value of UDV (User defined variables)
echo Command
Shell Arithmetic
More about Quotes
Exit Status
The read Statement
Wild cards (Filename Shorthand or meta Characters)
More commands on one command line
Command Line Processing
Why Command Line arguments required
Redirection of Standard output/input i.e. Input - Output redirection
Pipes
Filter
What is Processes
Why Process required
Linux Command(s) Related with Process
Chapter 3: Shells (bash) structured Language Constructs
Decision making in shell script ( i.e. if command)
test command or [ expr ]
if...else...fi
Nested ifs
Multilevel if-then-else
Loops in Shell Scripts
for loop
Nested for loop
while loop
The case Statement
How to de-bug the shell script?
Chapter 4: Advanced Shell Scripting Commands
/dev/null - to send unwanted output of program
Local and Global Shell variable (export command)
Conditional execution i.e. && and ||
I/O Redirection and file descriptors
Functions
User Interface and dialog utility-Part I
User Interface and dialog utility-Part II
Message Box (msgbox) using dialog utility
Confirmation Box (yesno box) using dialog utility
Input (inputbox) using dialog utility
User Interface using dialog Utility - Putting it all together
trap command
The shift Command
getopts command
Chapter 5: Essential Utilities for Power User
Preparing for Quick Tour of essential utilities
Selecting portion of a file using cut utility
Putting lines together using paste utility
The join utility
Translating range of characters using tr utility
Data manipulation using awk utility
sed utility - Editing file without using editor
Removing duplicate lines from text database file using uniq utility
Finding matching pattern using grep utility
Chapter 6: Learning expressions with ex
Getting started with ex
Printing text on-screen
Deleting lines
Coping lines
Searching the words
Find and Replace (Substituting regular expression)
Replacing word with confirmation from user
Finding words
Using range of characters in regular expressions
Using & as Special replacement character
Converting lowercase character to uppercase
Chapter 7: awk Revisited
Getting Starting with awk
Predefined variables of awk
Doing arithmetic with awk
User Defined variables in awk
Use of printf statement
Use of Format Specification Code
if condition in awk
Loops in awk
Real life examples in awk
awk miscellaneous
sed - Quick Introduction
Redirecting the output of sed command
How to write sed scripts?
More examples of sed
Chapter 8: Examples of Shell Scripts
Logic Development:
Shell script to print given numbers sum of all digit
Shell script to print contains of file from given line number to next given number of lines
Shell script to say Good morning/Afternoon/Evening as you log in to system
Shell script to find whether entered year is Leap or not
Sort the given five number in ascending order (use of array)
Command line (args) handling:
Adding 2 nos. suppiled as command line args
Calculating average of given numbers on command line args
Finding out biggest number from given three nos suppiled as command line args
Shell script to implement getopts statement.
Basic math Calculator (case statement)
Loops using while & for loop:
Print nos. as 5,4,3,2,1 using while loop
Printing the patterns using for loop.
Arithmetic in shell scripting:
Performing real number calculation in shell script
Converting decimal number to hexadecimal number
Calculating factorial of given number
File handling:
Shell script to determine whether given file exist or not.
Screen handling/echo command with escape sequence code:
Shell script to print "Hello World" message, in Bold, Blink effect, and in different colors like red, brown etc.
Background process implementation:
Digital clock using shell script
User interface and Functions in shell script:
Shell script to implements menu based system.
System Administration:
Getting more information about your working environment through shell script
Shell script to gathered useful system information such as CPU, disks, Ram and your environment etc.
Shell script to add DNS Entery to BIND Database with default Nameservers, Mail Servers (MX) and host
Integrating awk script with shell script:
Script to convert file names from UPPERCASE to lowercase file names or vice versa.
Chapter 9: Other Resources
Appendix - A : Linux File Server Tutorial (LFST) version b0.1 Rev. 2
Appendix - B : Linux Command Reference (LCR)
About the author
About this Document
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

버클리 데이터베이스는 트랜잭션을 관리해 주는 소스가 개방된 라이브러리형 데이터베이스로서 확장성과 성능이 뛰어나다. 다음 그림은 버클리 데이터베이스가 일반적인 관계형 데이터베이스와 어떤 구조적인 차이점이 있는지 잘 설명해 준다.

일반 관계형 데이터베이스는 독립된 프로그램으로 구성되어 애플리케이션과 따로 동작하면서 애플리케이션과 네트워크가 ‘inter process communication’을 통해 자료를 주고받는다. 하지만 버클리 데이터베이스는 컴파일 시 애플리케이션에 링크되어 애플리케이션의 메모리 어드레스를 함께 사용한다. Locking, 로그 관리, 메모리 관리 등과 같은 기본적인 모든 데이터베이스의 작동이 라이브러리 내에서 수행되고, 멀티 프로세스 또는 프로세스에 있는 멀티 쓰레드는 동시에 데이터베이스를 사용할 수 있다.
결과적으로 프로세스 간 통신이 사라지게 되어 시스템의 전체적인 구조가 간단해진다. 당연히 버클리 데이터베이스는 일반적으로 널리 사용되고 있는 언어인 Java, C, C++, Perl, Tcl, Phthon 그리고 PHP의 API를 제공해 준다.

또한 버클리 데이터베이스는 많은 플랫폼을 지원한다. 모든 유닉스와 리눅스 플랫폼, MS-Windows 플랫폼, 32bit, 64bit 플랫폼, 하이엔드 인터넷 서버(High-end Internet Server)나, 데스크톱 시스템, 노트북 등 모든 곳에서 운용이 가능하다고 볼 수 있다.

버클리 데이터베이스는 다음과 같은 기본적인 기능을 수행한다.

 

1. Page cache management
불필요한 I/O를 줄임으로써 빠른 데이터 접근을 지원한다.
2. Transaction and logging
데이터베이스 복구를 보장한다.
3. Locking
여러 사용자에 의한 다중 읽기 및 쓰기(multiple read/write)를 보장한다.

특히, 일반적인 관계형 데이터베이스와 차별화된 내용은 다음과 같다.

1. SQL 개념의 질의문은 지원되지 않는다.
2. 객체 지향적(Object Oriented)으로 설계되어 있지 않다.(버클리 데이터베이스는 C로 짜여졌다).
3. Network 기능이 없다.
4. 데이터베이스 서버가 아니다.

현재 버클리 데이터베이스는 4.2.X가 최신 버전이다. 비록 프리웨어지만, DB라는 이름에 걸맞게 여러 유틸리티 프로그램도 함께 제공한다.

#ls bin
db_archive*
db_checkpoint*
db_deadlock*
db_dump*
db_load*
db_printlog*
db_recover*
db_stat*
db_upgrade*
db_verify*

 

라이브러리의 구조는 다음과 같다.

#ls lib
db.jar
libdb-4.2.a
libdb-4.2.la
libdb-4.2.so*
libdb-4.so@
libdb.a
libdb.so@
libdb_java-4.2.a
libdb_java-4.2.la
libdb_java-4.2.so*
libdb_java-4.2_g.so@
libdb_java-4.so@
libdb_java.so@

해더 파일들은 무척이나 간단하다.

#ls include
db.h
db_cxx.h

 

버클리 데이터베이스는 데이터를 어떻게 관리할까? 먼저 데이터의 구조는 무척이나 간단하다. 데이터 파일에 저장되는 레코드의 구조는 다음과 같다.

SQL의 테이블, 컬럼 구조에 익숙한 개발자라면 위 표에서 Key, Value 구조의 막막함이 느껴질 것이다. 하지만 잘 짜여진 데이터 구조가 바탕에 있다면 Key, Value의 간단, 명료함은 그 가치를 나타낼 것이다.
위의 구조는 Java 객체중 Properties 객체와 유사하다. 이 구조를 바탕으로 데이터베이스는 레코드 삽입, 삭제, 수정, 그리고 찾기 기능을 수행한다.
여기서 알아두어야 할 중요한 사항은 Value 부분에 대해서는 전혀 오퍼레이션을 하지 않는다는 것이다. Value는 Key로 구분되는 데이터일뿐이다. 이는 Value 부분에 대한 찾기 기능이 없다는 뜻으로 특정 Value를 찾고자 한다면 그 Key 값이 무엇인지를 먼저 알아야 한다.

Key와 Value에 대한 특징은 다음과 같다.

1. Byte 형태의 값을 갖는다.
2. 길이는 고정적이거나 가변적이다.
3. Key나 Value에 대한 형태는 프로그래머에 의해 결정된다.
4. 최대크기는 4GB

네 가지 주요 특징 가운데 세 번째 특징은 프로그래머에게는 부담이 될 수도 있다. 버클리 데이터베이스는 Key와 Value를 의미가 없는 단순한 ‘byte string’으로 인식하고 그에 대한 정보를 하나도 갖고 있지 않기 때문이다. 따라서 Key와 Value가 의미를 갖기 위해서는 프로그래머가 미리 구조를 설계한 후 그 구조에 맞게 Key와Value 값을 가공하여 사용해야 한다. Key와 Value 구조를 모른다면 그 데이터베이스는 의미없는 Byte 덩어리일 뿐이다.

C나 C++로 개발하는 프로그래머일 경우에는 Struct 문장을 사용하여 Key와 Value 구조를 정의하여 사용할 수 있다. 개발 언어가 Java일 경우에는 Object Serialization을 통해 손쉽게 객체를 처리할 수 있다.

 

Key와 Value에 대한 정보가 없다는 것은 개발자나 애플리케이션의 측면에서 볼 때 넘어야 할 걸림돌이다. 모든 것을 프로그래머가 책임져야 한다. 하지만 이러한 특징을 역으로 생각한다면 Key 값과 Value 값에는 어떠한 값이든 넣을 수 있다는 또 다른 가능성도 같이 제공해 준다. 그림이나 사운드든 파일이나 문서든 데이터 형태에 구분받지 않고 Key와 Value 값으로 사용할 수 있는 셈이다. 물론 대부분의 관계형 데이터베이스도 이러한 기능을 지원해 준다.
지금까지는 버클리 데이터베이스가 일반 관계형 데이터베이스와 어떻게 다른지 간략하게 살펴보았다. 그럼 이제부터는 프로그래머가 맛있어 하는 소스를 맛보도록 하겠다. 다음 프로그램은 버클리 데이터베이스를 사용한 간단한 레코드 삽입 프로그램이다. 얼핏보면, isam을 이용한 자료 처리 프로그램과 유사하다.

● 레코드 입력 프로그램 <코드 1>

프로그램<코드 1>을 라인별로 간단히 설명해 보겠다.

12 라인 - 버클리 데이터베이스를 참조하기 위한 객체를 생성한다.
13 라인 - 에러 메세지가 출력될 스트림을 설정한다.
14 라인 - 에러 메세지에 출력될 메세지 prefix
15 라인 - 데이터 파일을 생성하거나 이미 존재하면 그것을 사용한다.


여기서 Open 함수 API의 정확한 정의는 다음과 같다.

public void open(DbTxn txnid, String file,
String database, int type, int flags, int mode)
throws DbException, FileNotFoundException


4번째 파라미터인 Db.DB_BTREE에 대해서는 다음 기회로 미루겠다.

17~30 라인 - Dbt라는 객체를 통해 데이터 파일에 있는 Key/Value를 사용할 수 있다. 24(29), 25(30) 라인에서는 각각 Byte 데이터와 크기를 설정했다.
33 라인 - Key 값과 Value 값을 데이터 파일에 저장한다. 이때 사용한 플래그는 Db.DB_NOOVERWRITE이다. 이 플래그가 설정되면 이미 존재하는 키 값을 저장할 경우 에러가 발생하고, Db.DB_ KEYEXIST 에러 값을 리턴한다. 기본적으로 버클리 데이터베이스는 오류가 없으면 0을 반환하게 되어 있다. 만약 에러가 발생한다면 0 이상의 값을 반환한다.
36 라인 - 데이터베이스 사용을 마친다. 만약 close를 입력하지 않는다면 저장한 데이터는 파일에 기록되지 않고 사라지게 된다. 이는 저장된 자료가 파일이 아닌 메모리의 캐시 영역에 저장되고 사용되기 때문이다. 따라서 추후 사용을 위해 반드시 close 함수나, sync() 함수를 호출해야 한다.

저장을 했으니, 이제 조회를 할 차례다.

● 레코드 조회 프로그램 <코드 2>

프로그램<코드 2>에 대해 라인별로 간단히 설명해 보겠다.

22, 23, 24 라인 - 데이터 검색을 위해 Key 값에 대해서만 찾고자 하는 값을 설정했다.
30 라인 - get method를 호출하여 검색을 한다. 해당되는 Key 값을 갖는 자료를 발견하면, Value 객체에 해당되는 값이 들어간다.
33 라인 - Value Dbt 객체에서 데이터를 갖고와 String으로 저장한다.

앞서 예로 든 두개의 프로그램은 버클리 데이터베이스의 저장 및 조회 프로그램의 기본적인 구조를 보여준다. 여기서 소개된 예제 프로그램은 기본에 충실한 간단한 것이다. 하지만 버클리 데이터베이스가 그리 간단하게 돌아가는 것은 아니다. 이번에는 소개를 하지 못했지만, 기본적인 사용법을 벗어난 다음과 같은 고급 기능들도 있다.
고급 기능에 대한 자세한 설명은 다음 기회로 미루고 이번에는 버클리 데이터베이스에 대한 첫 소개의 기회로 삼을까 한다.

1. cursor를 사용한 데이터 처리
2. DBEnv 객체를 이용한 데이터베이스 환경 사용
3. 4가지의 데이터 접근 방법(BTREE, HASH, QUEUE, REC_NO)
4. Object 객체화
5. Join 검색
6. Dbt의 파생 클래스
7. Sleepycat의 새로운 collection API
8. 트랜잭션 처리
9. locking
10. 로깅 관리
11. 데이터베이스 복구

 
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
By Agnes Jacob and Kelly Kishore, May 2002  

Introduction

Streaming media technology emerged as the web evolved from static to dynamic content. Many companies, educational institutions, and service and content providers have been using the web to broadcast live presentations, movies, concerts, educational programs, news, sports, and advertisements. Streaming technology allows these types of content to be viewed as it is transmitted without having to download the entire content onto client's local storage.

There are two types of streaming:

  • True Streaming uses RTP and RTSP (Real Time Protocol and Real Time Streaming Protocol) as the transport protocols, and there is a dedicated server where the source (multimedia files or live broadcast) is transmitted and viewed by the client.
  • Progressive Download uses HTTP (Hyper-Text Translation Protocol) as the transport protocol, with a regular web server. In this method, a portion of the video is downloaded onto the client's storage and begins playing before it is completely downloaded.

Multimedia files are usually compressed and encoded in certain formats on the server end and then decompressed and decoded by a media player on the client side. The formats that currently can be streamed include RealNetworks (*.rm), Windows Media (*.wmv, *.asf), QuickTime (*.mov), MPEG (*.mpg), audio files (*.mp3), and other video files (*.mp2).

Either type of streaming or multimedia source requires a scalable and efficient server with a fast storage solution and good network bandwidth to address the needs of streaming media applications. This paper describes how to tune servers running on the Solaris Operating Environment to improve performance for streaming media applications. These suggestions are based on observations while working with ISVs (independent software vendors) developing streaming media applications. The things to consider when tuning a server for media applications include network, I/O, and local and remote file systems.

Network Tuning

To take advantage of high-speed networks and thus increase network throughput, the Solaris platform offers tunable parameters for UDP and TCP, which are the underlying protocols for RTSP, RTP, and HTTP. The UDP and TCP tunables that are beneficial to streaming media applications relate to window size, buffer size, and checksumming.

Setting the TCP window size or UDP socket buffer size to the application read or write call size minimizes the fragmentation of the packets in the transport layer. For example, if the application server sends out or writes out 32 Kbyte, and the UDP socket buffer size is set to 8 Kbyte, then the server will break this 32-Kbyte request into 8-Kbyte packets before sending it over the network. By setting the UDP receive and send buffer size or TCP window size, you will reduce the overhead by reducing fragmentation and thus increase performance.

The tunables for UDP that would modify the socket buffer size include:

  • udp_xmit_hiwat - maximum UDP socket datagram in bytes (Default=8192)

  • udp_recv_hiwat - maximum UDP socket receive buffer size in bytes (Default=8192)

  • udp_max_buf - controls how large send and receive buffers (in bytes) can be for a UDP socket. This should be set to a value higher than the previous tunables, otherwise an error will be returned. (Default=256*1024)

The tunables for TCP that modify the window size include:

  • tcp_xmit_hiwat - maximum value of the TCP send window size in bytes (Default=16384)

  • tcp_recv_hiwat - maximum value of the TCP receive window size in bytes (Default=24576)

  • tcp_max_buf - controls how large the send and receive buffers can be (in bytes). This should be set to a value higher than the previous tunables, otherwise an error will be returned. (Default=1048576)

You can use ndd to modify these values. For example:

ndd -set /dev/udp udp_xmit_hiwat <value_in_bytes>

To maintain these settings across reboots, you should put a line for this in the file /etc/rc2.d/S69inet:

  #
  # Set configurable parameters.
  #
  ndd -set /dev/tcp tcp_xmit_hiwat  65536

Another way you could achieve a performance boost is to turn OFF this udp tunable:

  • udp_do_checksum - This enables UDP checksumming to ensure data integrity. (Default=1)

If your network card already has some sort of hardware checksumming, then this feature can be turned off to avoid double checks. Use ndd to turn this off (for example, ndd -set /dev/udp udp_do_checksum 0).

It is important to note that currently UDP is the desired protocol for streaming media because it does not make acknowledgments of packets or retransmissions. Since the audio or video is being listened to or viewed as it is transmitted, retransmission of lost bytes is not necessary. Also, if the stream can be multicasted (sent to one or more clients), UDP is the only protocol that supports this mode.

For Solaris servers that have Sun GigaSwift Ethernet adapter network cards (only supported in the line of servers that run on UltraSPARC III® processors), there are device driver parameters to consider for possible PCI interperformance improvements. The effects on performance vary among different applications, and it would be good to try out different values for these parameters.

The device parameters include:

  • tx_dma_weight - multiplication factor for granting priority to the transmit (TX) side during a weighted round-robin arbitration. The weight values are power of 2. (Default=0)

  • rx_dma_weight - multiplication factor for granting priority to the receive (RX) side during a weighted round-robin arbitration. The weight values are power of 2. (Default=0)

These tunables control the priority access to the PCI. For example, if the tx_dma_weight = 0 and the rx_dma_weight = 3, then the RX traffic will have 8 times greater priority over TX traffic.

Another device driver parameter adjustment that may improve performance is to turn on infinite_burst:

  • infinite_burst - allows the adapter to not free the bus until packets are transferred across the bus (Default=0)

For large packets, turning this parameter ON could be beneficial. Use ndd to set these device parameters or set these values in the ce.conf file. (For example, with ndd -set /dev/ce <parameter> <value>, you need to set the instance number to select the device if multiple devices are active.)

In addition, for good bus performance with Sun GigaSwift Ethernet adapters, use a 66-MHz, 64-bit PCI slot to take advantage of the faster, wider bus. Also, select a slot that does not share bus bandwidth with other slots.

I/O Tuning

Multimedia files can be located local to the server, on a remote server, or on a SAN (storage area network). For streaming media applications, sequential read/write access is the most predominant I/O disk operation since the multimedia files are stored on disk before they are transmitted (except for live broadcast). Thus selection and configuration of the storage device are factors that can affect overall performance. Configuration of your I/O disk devices as stripe or utilizing hardware stripe (RAID 0, RAID 5) would be optimal for sequential access since the data can be spread across several disks and retrieved in parallel. If you choose to configure the disks as stripe, the stripe size should be a multiple of the read/write size to make the access more efficient.

The numerous ways to optimize I/O are beyond the scope of this paper; however, these two books are good references for planning disk layout:

  • Configuration and Capacity Planning for Solaris Servers, Brian Wong, Sun Microsystems Press, 1997 

  • Sun Performance and Tuning, Java and the Internet, 2nd Edition, Adrian Cockcroft and Richard Pettit, Sun Microsystems Press, 1998

File System Tuning

The types of file systems that are supported on the Solaris Operating Environment include UFS, VxFS, QFS, and NFS (for remote files). For each of these file system types, there are tuning considerations that relate to directio and blocksize. Also, for NFS, other NFS tunables and parameters can be set for better NFS throughput.

If your streaming media application accesses very large files and does not redistribute the same file often, mounting the file system with the directio option will increase file access performance. Mounting the file system with the directio option bypasses the kernel buffer cache (paged I/O) when reading and writing to disk. This reduces the CPU overhead considerably since the read/write goes directly to disk instead of copying the data between the kernel buffer and user buffer. For an I/O operation to be performed as direct I/O, it must meet the alignment criteria. The read/write request must be aligned to a sector, block size, or stripe size boundary, or it will buffer the I/O. Use mount with forcedirectio option to mount the file system as directio (for example, in UFS: mount -F ufs -o forcedirectio <device> <mountpt>).

Multimedia files consisting of high bit rate audio and video can be in the gigabyte file size range. Tuning the file system block size or extent size can definitely improve performance for larger files. Currently the maximum block size or extent size supported for UFS and VxFS, respectively, is 8 Kbyte. For larger files, there is an extra layer of indirection to access the rest of the data or an increase in the number of data blocks or extents used per file; this creates extra overhead when accessing large files. QFS, however, supports variable block sizes up to a maximum of 32 Mbyte. For a 64-Mbyte file, it requires only 2 data blocks to represent this file, however, in UFS or VXFS it would require 8000 data blocks or extents to represent this file, and it would require another level of indirection. Thus, consider using the largest possible block sizes when creating the file system. Use the mkfs command with the correct option for each of the file systems to set the block size.

Files on a remote server reside on a network file system (NFS). The overall performance of NFS is affected by the underlying file system type, I/O (disk layout), network bandwidth, and performance of the remote server. However, you can consider NFS (network file system) tunables to improve NFS throughput.

One tunable is:

  • nfs3_max_transfer_size - maximum size of the data portion of an NFS version 3 READ, WRITE, READDIR, or READDIRPLUS request (Default=32KB)

It would be best to tune the maximum transfer size to the size of the data being passed over the network, for example, the read/write I/O request size. However, depending on the configuration of the remote server and network bandwidth, you need to tune this value as closely as you can to the read/write I/O request size without degrading performance on the server. If you modify this parameter, you would also need to modify the parameter nfs3_bsize, otherwise the over-the-wire request size would be limited to the nfs3_bsize.

  • nfs3_bsize - the logical block size used by the NFS version 3 client. This block size represents the amount of data that the client attempts to read from or write to the server when it needs to do an I/O. (Default=32KB)

These NFS tunables need to be applied to both the client and server. For UDP, there is a hard limit of 64 Kbyte per datagram (including headers and data) for the max_transfer_size.

To modify these values, you would need to set them in the /etc/system file, and it would require a reboot for the values to take effect. For example, the contents of /etc/system could be:

nfs:nfs3_max_transfer_size=65536
nfs:nfs3_bsize=65536

Also, increasing the number of NFS threads (nfsd) on a server enables the server to handle more NFS requests in parallel. For streaming media applications that require access to remote files, setting this to a higher value would provide increased NFS throughput. How to set this parameter would depend on the size of the server. A rule of thumb is to take the maximum of the following:

  1. Use 16 to 32 NFS threads for each CPU.
  2. Use 2 NFS threads for each active client.
  3. Use 16 NFS threads for each 10 Mbit of network capacity.

To set the NFS threads, you would need to modify the /etc/init.d/nfs.server to start nfsd with the specified amount of threads.

Summary

As streaming media technology continues to expand and grow, different demands and needs will arise, and system tuning will change to address these needs. This paper focuses on parameters you can tune for streaming media applications on servers running on the Solaris platform. Other tunable parameters may exist for enhancing performance for these applications. However, so far, these are the tuning suggestions that we have found to produce the greatest improvement in performance for streaming media applications on these servers.

References

  • Sun Performance and Tuning, Java and the Internet, 2nd Edition, Adrian Cockcroft and Richard Pettit, Sun Microsystems Press, 1998 

  • Configuration and Capacity Planning for Solaris Servers, Brian Wong, Sun Microsystems Press, 1997 

  • "NFS Server Performance and Tuning Guide for Sun Hardware," Sun Microsystems, 2000 

  • "Platform Notes: Sun GigaSwift Ethernet Device Driver" from Solaris 8 10/01 on Sun Hardware Collection, Sun Microsystems, 2001 

  • "QFS - Technical Overview v3.4/3.5," LSC, Inc. (now Sun Microsystems), March 9, 2000 

  • "Solaris Tunable Parameters Reference Manual" from Solaris 8 10/01 Update Collection, Sun Microsystems, 2001 

  • "VxFS System Administrator's Guide," VERITAS Corporation, 2000 

About the Authors

Agnes Jacob is a staff engineer in Sun Market Development Engineering, working with ISVs to improve performance of their applications on Sun servers by means of tuning and sizing studies. Her experience includes kernel development in the areas of file system, I/O, and network file system, as well as Java technology.

Kelly Kishore has been working with streaming media technologies since 2000. At Sun, he is currently in Market Development Engineering, working with digital media customers.

May 2002