Scalable Architecture Design
DEVIEW 2013 에서 발표한 "오픈소스를 활용한 분산 아키텍처 구현기술" 장표입니다.
Scalable Architecture 디자인을 위해 필요한 다양한 구현 기술 중 몇가지를 소개해 드립니다.
관련된 내용으로 문의 있으시면 메일로 연락 주세요~
23. 1 Scalability
When you add twice as many servers, are you twice as fast
(or have twice the capacity)?
- LiveJournal
https://www.usenix.org/legacy/events/usenix07/tech/slides/fitzpatrick.pdf
Replacing all components of a car while driving it at
100mph.
- Instagram
https://www.unboundid.com/blog/2012/06/27/scaling-at-100mph
174. 4.1 Consistent Hashing
public
class
ConsistentHashT{
ConsistentHash.add(‘nodeA’,...);
private
final
HashFunction
hashFunction
=
Hashing.md5();
private
final
SortedMapLong,
T
circle
=
new
TreeMapLong,
T();
ConsistentHash.add(‘nodeB’,...);
ConsistentHash.add(‘nodeC’,...);
public
void
add(String
name,
T
node)
{
circle.put(hashFunction.hashString(name).asLong(),node);
}
public
void
remove(String
name)
{
circle.remove(hashFunction.hashString(name).asLong());
}
ConsistentHash.add(‘nodeD’,...);
}
public
T
get(String
value)
{
long
hash
=
hashFunction.hashString(value).asLong();
if
(!circle.containsKey(hash))
{
SortedMapLong,
T
tailMap
=
circle.tailMap(hash);
hash
=
tailMap.isEmpty()?circle.firstKey():tailMap.firstKey();
}
return
circle.get(hash);
}
175. 4.1 Consistent Hashing
public
class
ConsistentHashT{
private
final
HashFunction
hashFunction
=
Hashing.md5();
private
final
SortedMapLong,
T
circle
=
new
TreeMapLong,
T();
private
final
int
numberOfReplicas
=
100;
}
public
void
add(String
name,
T
node)
{
for
(int
i
=
0;
i
numberOfReplicas;
i++)
{
circle.put(hashFunction.hashString(name
+
i).asLong(),node);
}
}
public
void
remove(String
name)
{
for
(int
i
=
0;
i
numberOfReplicas;
i++)
{
circle.remove(hashFunction.hashString(name
+
i).asLong());
}
}
public
T
get(String
value)
{
long
hash
=
hashFunction.hashString(value).asLong();
if
(!circle.containsKey(hash))
{
SortedMapLong,
T
tailMap
=
circle.tailMap(hash);
hash
=
tailMap.isEmpty()?circle.firstKey():tailMap.firstKey();
}
return
circle.get(hash);
}
176. 4.1 Consistent Hashing
public
class
ConsistentHashT{
}
private
final
HashFunction
hashFunction
=
Hashing.md5();
private
final
SortedMapLong,
T
circle
=
new
TreeMapLong,
T();
private
final
int
numberOfReplicas
=
100;
모두
179. 하나?
public
void
add(String
name,
T
node)
{
for
(int
i
=
0;
i
numberOfReplicas;
i++)
{
circle.put(hashFunction.hashString(name
+
i).asLong(),node);
서버의
187. 고려
}
}
public
void
remove(String
name)
{
for
(int
i
=
0;
i
numberOfReplicas;
i++)
{
circle.remove(hashFunction.hashString(name
+
i).asLong());
}
}
public
T
get(String
value)
{
long
hash
=
hashFunction.hashString(value).asLong();
if
(!circle.containsKey(hash))
{
SortedMapLong,
T
tailMap
=
circle.tailMap(hash);
hash
=
tailMap.isEmpty()?circle.firstKey():tailMap.firstKey();
}
return
circle.get(hash);
}