HadoopとHiveに再び超ハマる

まだハマりどころがありました.
Apache Hiveにハマり続けている毎日 - なぜか数学者にはワイン好きが多い


HadoopはCDH5をAmazon EC2上に構築しています.
データノードはm3.2xlargeを使っていたのですが,ただのSELECTにパーティション以外のカラムにWHERE一個付けただけでCPUを振り切ってload averageが20くらいになるので,まずはc3.8xlargeにしてみました.コア数もメモリも増えて良い感じでした.
するとジョブは走るようになったのですが,結局MapとReduceが100%になった時点で次のエラーが返ってきて結果は出ません.

java.lang.OutOfMemoryError: GC overhead limit exceeded

普通にジョブを走らせたりHadoop Streamingを走らせても見たことは無かったのですが...

仕方がなく,mapred-site.xmlを書き換えました.

<property>
  <name>mapred.child.java.opts</name>
  <value>-Xmx200m</value>
  <description>Java opts for the task tracker child processes.  
  The following symbol, if present, will be interpolated: @taskid@ is replaced 
  by current TaskID. Any other occurrences of '@' will go unchanged.
  For example, to enable verbose gc logging to a file named for the taskid in
  /tmp and to set the heap maximum to be a gigabyte, pass a 'value' of:
        -Xmx1024m -verbose:gc -Xloggc:/tmp/@taskid@.gc
  
  Usage of -Djava.library.path can cause programs to no longer function if
  hadoop native libraries are used. These values should instead be set as part 
  of LD_LIBRARY_PATH in the map / reduce JVM env using the mapreduce.map.env and 
  mapreduce.reduce.env config settings. 
  </description>
</property>

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

<property>
  <name>mapred.child.java.opts</name>
  <value>-Xmx1024m</value>
  <description>Java opts for the task tracker child processes.  
  The following symbol, if present, will be interpolated: @taskid@ is replaced 
  by current TaskID. Any other occurrences of '@' will go unchanged.
  For example, to enable verbose gc logging to a file named for the taskid in
  /tmp and to set the heap maximum to be a gigabyte, pass a 'value' of:
        -Xmx1024m -verbose:gc -Xloggc:/tmp/@taskid@.gc
  
  Usage of -Djava.library.path can cause programs to no longer function if
  hadoop native libraries are used. These values should instead be set as part 
  of LD_LIBRARY_PATH in the map / reduce JVM env using the mapreduce.map.env and 
  mapreduce.reduce.env config settings. 
  </description>
</property>

そしてHiveからクエリを出してデータノードのjavaのプロセスを監視してみると...

20287 ?        Sl     3:17 /usr/local/jdk/bin/java -Djava.net.preferIPv4Stack=true -Dhadoop.metrics.log.level=WARN -Xmx200m -Djava.io.tmpdir=/data/tmp/hadoop-hadoop/nm-local-dir/usercache/hadoop/appcache/application_1402968460509_0024/container_1402968460509_0024_01_000003/tmp -Dlog4j.configuration=container-log4j.properties -Dyarn.app.container.log.dir=/usr/local/hadoop/logs/userlogs/application_1402968460509_0024/container_1402968460509_0024_01_000003 -Dyarn.app.container.log.filesize=0 -Dhadoop.root.logger=INFO,CLA org.apache.hadoop.mapred.YarnChild 191.168.1.1 37394 attempt_1402968460509_0024_m_000001_0 3

-Xmx200mって出ていて,やっぱりGC overhead limit exceededが出ます.
jstatでGCの様子を調べようと思ったのですが,数秒でスレッドが消えるのでvmidを指定することができません.
userlogを見てみると,メモリが180mバイトくらいで落ちている感じで,間違いなくヒープサイズが効いていると思われました.
ふと思って,HiveQLでmapred.child.java.optsを指定すると,クエリは完了しました.

hive -e "set mapred.child.java.opts=-Xmx1024m; SELECT name, count(name) FROM members WHERE name LIKE 'A%' GROUP BY name"

ならば良いかと言うとよろしくなくて,同僚がshibを使っているので,この指定は取っ払いたかったです.
Hive Client Webアプリケーション shib をつくった - たごもりすメモ

一度にひとつのクエリのみで、セミコロンが入ってたらエラー

試してみると,ちゃんとエラーになりました.

結論.
Hiveの設定で動作が変化するということは,Hadoop側じゃなくてHiveがおかしい.
つまり,

<property>
  <name>mapred.child.java.opts</name>
  <value>-Xmx1024m</value>
  <description>Java opts for the task tracker child processes.  
  The following symbol, if present, will be interpolated: @taskid@ is replaced 
  by current TaskID. Any other occurrences of '@' will go unchanged.
  For example, to enable verbose gc logging to a file named for the taskid in
  /tmp and to set the heap maximum to be a gigabyte, pass a 'value' of:
        -Xmx1024m -verbose:gc -Xloggc:/tmp/@taskid@.gc
  
  Usage of -Djava.library.path can cause programs to no longer function if
  hadoop native libraries are used. These values should instead be set as part 
  of LD_LIBRARY_PATH in the map / reduce JVM env using the mapreduce.map.env and 
  mapreduce.reduce.env config settings. 
  </description>
</property>

は,hive-site.xmlにも書かなければいけない.

ヒープを200メガから1ギガに変えただけで,Hiveが無事動くようになりました.というかEC2のインスタンスも良いのに変えていたので,爆速になりました.
shibからも問題なしです.