'2017/07/27'에 해당되는 글 3건

  1. 2017.07.27 [scala] scalatest에서 Exception 처리
  2. 2017.07.27 [scala] scalablitz
  3. 2017.07.27 [hive] reducer에 메모리 할당하기


scalatest에서 Exception처리하는 예제이다. 


다음과 같은 포맷으로 개발한다. 


intercept[Exception] {

   메소드

}


import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class AppSuite extends FunSuite {

test("test") {
checkParam("a")
}

test("null test") {
intercept[IllegalArgumentException] {
checkParam(null)
}
}

def checkParam(param: String): Int = param match {
case null => throw new IllegalArgumentException("None is illegal.")
case _ => 0
}

}


Posted by '김용환'
,

[scala] scalablitz

scala 2017. 7. 27. 19:49

coursera의 scala 강의 중에 scalablitz의 흔적(monoid 설명)이 있어서 함 찾아봤다.



scala 2.9(2011년)부터 parallel 패키지가 추가되었다. 


그러나 3rd party로 scalablitz(http://scala-blitz.github.io/)로 있긴 했지만, 2014년 쯔음부터는 더 이상 운영되지 못했다. 이제는 역사속으로 사진 라이브러리이지만... 


Parallel Collections were originally introduced into Scala in release 2.9. Why another data-parallel collections framework? While they provided programmers with seamless data-parallelism and an easy way to parallelize their computations, they had several downsides. First, the generic library-based approach in Scala Parallel Collections had some abstraction overheads that made them unsuitable for certain types of computations involving number crunching or linear algebra. To make efficient use of parallelism, overheads like boxing or use of iterators have to be eliminated. Second, pure task-based preemptive scheduling used in Scala Parallel Collections does not handle certain kinds of irregular data-parallel operations well. The data-parallel operations in this framework are provided for a wide range of collections, and they greatly reduce both of these overheads.




libraryDependencies += "com.github.scala-blitz" %% "scala-blitz" % "1.1"



스칼라의 병렬 콜렉션은 scala.collection.par 패키지를 이용할 수 있다. 스칼라 병렬 콜렉션처럼 일반 콜렉션에서 toPar 메소드를 호출하면 병렬 객체를 리턴한다. 


import scala.collection.par._
import scala.collection.par.Scheduler.Implicits.global

def mean(a: Array[Int]): Int = {
val sum = a.toPar.reduce(_ + _)
sum / a.length
}

val m = mean(Array(1, 3, 5))
print(m)

결과 값은 3이다.



이후에 예제 코딩을 진행하면 기존 스칼라 코드와 충돌이 나면서 테스트를 계속하기 애매해진다.


Error:(25, 5) reference to text is ambiguous;

it is both defined in method totalLength and imported subsequently by 

import scala._




slideshare에서 scalablitz 맛을 보는데 도움이 되는 것 같다. generic 관련해서 깔끔해진 느낌이 있긴 하다.. 

(가뜩이나 스칼라는 공부할수록 복잡해지는 느낌이 있긴 하다.......)


ScalaBlitz from Aleksandar Prokopec



더 궁금하면 아래 링크를 참조한다.


http://apprize.info/programming/scala/7.html


Posted by '김용환'
,






hive 쿼리를 실행시 reducer에 메모리 용량를 많이 할당해야 할 때가 있다.


이 때는 hive.exec.reducers.bytes.per.reducer를 설정하면 된다.



reducer 당 메모리 크기를 설정한다.설정된 메모리 크기를 바탕으로 reducer 개수를 정의한다.  Hive 0.14.0 이후 버전의 hive.exec.reducers.bytes.per.reducer 기본값은 256MB이다. 입력 크기가 1GB이면 4개의 reducer가 적당하는 것이다. 



https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties 문서를 보면 다음과 같다.


hive.exec.reducers.bytes.per.reducer
  • Default Value: 1,000,000,000 prior to Hive 0.14.0; 256 MB (256,000,000) in Hive 0.14.0 and later
  • Added In: Hive 0.2.0; default changed in 0.14.0 with HIVE-7158 (and HIVE-7917)

Size per reducer. The default in Hive 0.14.0 and earlier is 1 GB, that is, if the input size is 10 GB then 10 reducers will be used. In Hive 0.14.0 and later the default is 256 MB, that is, if the input size is 1 GB then 4 reducers will be used.



Hive 0.14.0이전의 기본 값은 1G이지만, 0.14.0이후에는 256MB이다. 256MB는 가장 성능이 잘나오는 HDFS 블럭 사이즈이라 한다. (https://stackoverflow.com/questions/34419869/how-to-set-data-block-size-in-hadoop-is-it-advantage-to-change-it참조)



이외 너무 많은 reducer를 쓰지 않도록 hive.exec.reducers.max의 값을 수정할 수 있다.

hive.exec.reducers.max
  • Default Value: 999 prior to Hive 0.14.0; 1009 in Hive 0.14.0 and later
  • Added In: Hive 0.2.0; default changed in 0.14.0 with HIVE-7158 (and HIVE-7917)

Maximum number of reducers that will be used. If the one specified in the configuration property mapred.reduce.tasks is negative, Hive will use this as the maximum number of reducers when automatically determining the number of reducers.





잡마다 reduce의 기본 개수를 정의할 수 있다.


mapred.reduce.tasks
  • Default Value: -1
  • Added In: Hive 0.1.0

The default number of reduce tasks per job. Typically set to a prime close to the number of available hosts. Ignored when mapred.job.tracker is "local". Hadoop set this to 1 by default, whereas Hive uses -1 as its default value. By setting this property to -1, Hive will automatically figure out what should be the number of reducers.


Posted by '김용환'
,