스칼라의 콜렉션은 Immutable, mutable 말고

병렬 콜렉션(Par...)와 순차 콜렉션(일반적으로 사용하는 콜렉션)과 상위 클래스(Gen...)으로 나눠진다. 

참고로 Gen은 general의 약자이다. 



출처: http://docs.scala-lang.org/overviews/parallel-collections/architecture.html




아래의 예를 보면 기본 콜렉션인 Array에 par 함수를 호출하면서 병렬 콜렉션인 ParArray를 인스턴스로 얻는다.

val parArray = (1 to 100).toArray.par

parArray: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)





http://docs.scala-lang.org/overviews/parallel-collections/overview.html 에 병렬 콜렉션에 대한 예제가 있는데 심플해서 도움이 된다.



map 예제

val lastNames = List("Smith","Jones","Frankenstein","Bach","Jackson","Rodin").par
lastNames.map(_.toUpperCase)

lastNames: scala.collection.parallel.immutable.ParSeq[String] = ParVector(Smith, Jones, Frankenstein, Bach, Jackson, Rodin)

res7: scala.collection.parallel.immutable.ParSeq[String] = ParVector(SMITH, JONES, FRANKENSTEIN, BACH, JACKSON, RODIN)




fold 예제

val parArray = (1 to 100).toArray.par
parArray.fold(0)(_ + _)

parArray: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)

res5: Int = 5050




filter 예제

val lastNames = List("Smith","Jones","Frankenstein","Bach","Jackson","Rodin").par
lastNames.filter(_.head >= 'f')

lastNames: scala.collection.parallel.immutable.ParSeq[String] = ParVector(Smith, Jones, Frankenstein, Bach, Jackson, Rodin)

res7: scala.collection.parallel.immutable.ParSeq[String] = ParVector(Smith, Jones, Jackson, Rodin)





성능을 높이는 splitter와 combiner(builder)에 대한 정보는 coursera 강의를 참조할 수 있다.
https://github.com/rohitvg/scala-parallel-programming-3/wiki/Splitters-and-Combiners





아래 자료를 보면 병렬 콜렉션의 장점(속도)를 알 수 있고 병렬 콜렉션의 이해도, custom splitter/builder 내용이 담겨 있다.


Scala Parallel Collections from Aleksandar Prokopec






Posted by '김용환'
,


스칼라의 콜렉션의 fold와 reduce와 scan 함수는 시간이 조금만 지나면 혼동되기 쉬운 것 같다. 

accumulate 기능이 있어서 서로 비슷하게 생겼다..





List(1,2,3).foldLeft(100)((s,x) => s - x)

((100 - 1) - 2) -3 = 94 




List(1,2,3).foldRight(100)((s,x) => s - x)

1 - (2 - (3 - 100)) = -98




List(1,2,3).reduceLeft((s,x) => s - x)

(1 - 2) - 3 = -4




List(1,2,3).reduceRight((s,x) => s - x)

1 - ( 2 - 3) = 2






List(1,2,3).scanLeft(100)((s, x) => s - x)

List(100, 100-1, (100-1)-2, (100-1)-2-3) 

=> List(100, 99, 97, 94)





List(1,2,3).scanRight(100)((s, x) => s - x)

// index3 : 초기값 100

// index2 : 3 - 100 = -97

// index1 : 2 - -97 = 99

// index0 : 1 - 99 = -98

List(-98, 99, -97, 100)

Posted by '김용환'
,

..

'Cloud' 카테고리의 다른 글

[펌] 한국 오픈 스택 2017 자료 올라옴  (0) 2017.08.16
[펌] fluentd 사용 사례  (0) 2017.08.15
처음 본 오픈스택 Swift  (0) 2017.07.24
처음 본 오픈 스택 Glance  (0) 2017.07.21
처음 본 오픈 스택의 Nova  (0) 2017.07.20
Posted by '김용환'
,


elasticsearch 5.0에서 사라진 api를 확인하고 싶다면.. 아래 페이지에 접근한다.


https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_search_changes.html



변경 사항과 삭제된 api를 볼 수 있다.


예를 들어, 삭제된 api는 다음과 같다.


Deprecated queries removededit

The following deprecated queries have been removed:

filtered
Use bool query instead, which supports filter clauses too.
and
Use must clauses in a bool query instead.
or
Use should clauses in a bool query instead.
missing
Use a negated exists query instead. (Also removed _missing_ from the query_string query)
limit
Use the terminate_after parameter instead.
fquery
Is obsolete after filters and queries have been merged.
query
Is obsolete after filters and queries have been merged.
query_binary
Was undocumented and has been removed.
filter_binary
Was undocumented and has been removed.




그리고, filtered query의 경우는 아래의 url에 접근할 수 있지만. 자세히 살펴보면 deleted page로 되어 있다..(즉 삭제된 api를 의미한다)


https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-filtered-query.html

Posted by '김용환'
,



오픈 스택의 swift(https://github.com/openstack/swift)은 object stroage이다. 


동영상, 이미지, 디스크 이미지등을 저장할 수 있는 저장공간이다. 


HTTP/HTTPS REST api를 이용해 데이터를 저장할 수 있다. 





출처 : https://docs.openstack.org/security-guide/object-storage.html




 RAID가 없기 때문에 가격이 싸고 S3 API를 지원하며 스케일링을 쉽게 진행할 수 있다. 중앙 DB가 없고 TTL을 지원하는 많은 기능을 가지고 있다. https://docs.openstack.org/swift/latest/admin/objectstorage-features.html을 살펴보면 더 자세한 내용을 확인할 수 있다. 


FeaturesBenefits
Leverages commodity hardwareNo lock-in, lower price/GB.
HDD/node failure agnosticSelf-healing, reliable, data redundancy protects from failures.
Unlimited storageLarge and flat namespace, highly scalable read/write access, able to serve content directly from storage system.
Multi-dimensional scalabilityScale-out architecture: Scale vertically and horizontally-distributed storage. Backs up and archives large amounts of data with linear performance.
Account/container/object structureNo nesting, not a traditional file system: Optimized for scale, it scales to multiple petabytes and billions of objects.
Built-in replication 3✕ + data redundancy (compared with 2✕ on RAID)A configurable number of accounts, containers and object copies for high availability.
Easily add capacity (unlike RAID resize)Elastic data scaling with ease.
No central databaseHigher performance, no bottlenecks.
RAID not requiredHandle many small, random reads and writes efficiently.
Built-in management utilitiesAccount management: Create, add, verify, and delete users; Container management: Upload, download, and verify; Monitoring: Capacity, host, network, log trawling, and cluster health.
Drive auditingDetect drive failures preempting data corruption.
Expiring objectsUsers can set an expiration time or a TTL on an object to control access.
Direct object accessEnable direct browser access to content, such as for a control panel.
Realtime visibility into client requestsKnow what users are requesting.
Supports S3 APIUtilize tools that were designed for the popular S3 API.
Restrict containers per accountLimit access to control usage by user.




이해에 도움되는 swift 슬라이드 자료이다 .


Openstack Swift overview from 어형 이


Posted by '김용환'
,