Skip to main content

Posts

Showing posts from 2014

Extending CentOS disk space (adding more lvm)

How to extend filesystem capacity in hadoop data node? First, attach your new hard drive to your PC (or add virtual hard drive if you are running on VirtualBox) Mount gParted ISO on your CentOS node. Boot with gParted. Create partition table for new hard drive: Device > Create Partition Table>  GPT is recommended Create new partition: "lvm2 pv" is recommended Boot CentOs Stop hadoop services on node. fdisk -l vgextend vg_hadoop2 /dev/sdb1 lvdisplay lvextend -L+8.48G /dev/vg_hadoop2/lv_root resize2fs -F /dev/vg_hadoop2/lv_root df -h That's it

Tashkent House Price Analysis

Recently  I've got an idea to analyze prices of houses in Tashkent city. " www.zor.uz " is one of the most famous sites where people sell houses, cars, electronics and etc. I had to crawl it and collect data from it. Unfortunately, "www.zor.uz" does not have the old data, the latest data that  I found there was just one month old. They seem to clean their DB every month. I needed data for previous years. So, I used "Way Back Machine" that has captured points of all website around the world. It is really a cool stuff to try :  https://archive.org/index.php But they use "https" so I had download their certificate and register it to my JRE. I crawled that site and succeeded to get data starting from 2009.08 (that was the earliest capture point of www.zor.uz) Interestingly "WayBackMachine" captures websites periodically, depending how often website changes. They have their own logic to capture sites for optimizing their stora

Why it is better not to use VirtualBox(VMWare etc..)

Cons 1. VirtualBox can not use full 100% resources of PC. Your hadoop will not be as fast as you expect. 2. You have to start virtual nodes whenever your reboot your PC (unless if you made some auto-start scripts) 3. Several virtual nodes in the same PC can cause mismanagement of resources. If RAM usage of VirtualBox nodes exceeds the maximum then your PC just crashes. Though, VirtualBox is a good starting point to build experimental hadoop environment. Pros 1. You can create several nodes in the same PC (if you lack PCs) 2. VirtualBox has Export /Import features that helps you to do "Do once - Copy many"  3. Do experiments by changing hardware features (add CPUs, reduce RAM etc..) For learning hadoop VirtualBox can be helpful to build hadoop environment. However, for production purpose it is better to avoid Virtualbox and use PC itself as a single node.

Hbase: 'Put' Performance Tuning

When you have millions of data to insert into Hbase, use bulk method which increases Put speed. Make sure to turn off AutoFlush option to False. HTable tableTermMatrix = new HTable(conf, TABLE_Matrix ); tableTermMatrix.setAutoFlush( false ); Then inside your data insertion loop: tableTermMatrix.put(put); cnt++; if (cnt>=5000) { cnt=0; tableTermMatrix.flushCommits(); } which will flush the data to RegionServer once for 5000 entries. For me, after using this bulk method total insertion time into HBase changed from 60 minutes to 2.5 minutes.

Streaming Twitter tweets to HBase with Apache Flume

            Apache Hbase is a great noSQL database for storing enormous amount of data that can scale in three axis. Apache Hbase was based on Google's BigTable that stores all  web contents in internet. By knowing row key and column id we can retrieve the value at the matter of milliseconds. HBase runs on top of HDFS and friendly with MapReduce tasks. So it can scale up together with Hadoop. One thing which seems to be disadvantage is HBase depends on ZooKeeper, while other big table based databases like Cassandra is independent. Nevertheless, I did not face any problem with it. Apache Hbase is really fast. Currently I am using it for TF-IDF based keyword retrieval, and it can retrieve results from 2 million tweets in few seconds. Anyways, Let me get back to the topic. My plan was to stream twitter data directly to Hbase by using Apache Flume. Fortunately, Flume has a Hbase sink plugin that comes by default in lib folder. We can use two kinds of sinks : HBaseSink and AsyncH

ThreeJs : South Korea's Entry statistics from Asia

     By using ThreeJS (HTML5 supported library) I have been modifying existing code and visualizing the amount of people's entry to South Korea from various countries of Asia. Japan and China is on the top.

Building Term Matrix on HBase and Calculating TF-IDF

     Finding term's related terms in real-time would not be easy if you have 2 millions of tweets and 10 millions of words. Although Hadoop can process huge amount of data in parallel it is not real-time. What if we want to see top  related words for the term "축구" in real-time. Top related words can be found by calculating TF(Term frequency) values for each word a certain set of documents. Then we calculate IDF(Inverted Document Frequency) values by looking at all documents. IDF helps to exclude  meaningless words (이, 다, 나, 너, 니, 하고, 보다  and so on) . Then We calculate TFIDF and sort all of them by the same values. Check out TFIDF on wiki:  http://en.wikipedia.org/wiki/Tf%E2%80%93idf The process is quite complicated, but I will try to explain it as simple as possible. Here are the steps that I went through: 1. Extracting tweetId and the term from Hive into a Text file.    By using Hive I split each tweet into words and separated each word in a line with its corr

Solving java.lang.ClassNotFoundException problem while exporting Jar file from Eclipse

While running my compiled jar files on hadoop cluster I faced this error many times: Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration Usually, I don't use maven and attach libraries manually to the project. The libraries that I use are mostly apache's libraries related to hadoop, hive, hbase and etc.. After successful compilation I export the project as a Jar file. I tried to export in many ways but I faced this ClassNotFoundException every time. So I realized that exporting my project with attached jar libraries is not the optimal solution for the problem. Then I found this solution on StackOverflow http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt It describes the way how to add required (dependency) jar files while running the main jar. It is simple! You just put all jars into the same folder where your main jar file is and Run: >java -cp *:. com.kh.demo.RealtimeTFIDF Note

ThreeJs - 3D data visualization on web

     I was into 3D since high school years. My first experience was making 3D models with 3Dsmax. Since few years back Google Chrome had been trying to bring this technology to all desktops through web. With the rise of HTML5 it became possible to render 3D on client side by using WebGL via javascript. However, using WebGL via Javascript was not easy so open-source communities developed various wrapper libraries to simplify using webGL.    Among them ThreeJS ( http://threejs.org/ ) is one the best choice to use IMHO. It is more mature comparing to others, and there are many examples to follow. It is better to see rather than reading, Check out this ThreeJS example:  http://www.georgeandjonathan.com/#6 Is not it amazing? Dynamic, interactive and open-source 3D visualization directly on your Chrome Browser. It runs on the latest Android Tablets and Phones too. In few years, I think everyone will be able to browse 3D sites on their devices. So, by using this library I am tryi

Korean NLP on Hive

These days I am building a small platform for doing "Topic Modeling" with Apache Mahout. While working on this project I tried to maximize the speed of NLP processing as fast as possible. Previously, I was running NLP on a single node after retrieving the tweet messages from Hive. Then I found out about UDF(User Defined Functions) which makes it possible to run custom libraries on Hadoop nodes during the mapping process of MapReduce. By using UDF, I  attached open-source Korean NLP library Hannanum and made a library to process NLP and Text processing parallel. Here is how the hive query looks like: >select extractNoun(text) from twitter; I put the source code on GitHub Feel free to use and ask questions. Here is my K-Means dumped cluster output (processing k=100 topics with one-day tweet data) Output.txt

Hive: Creating External Table from existing one

   Apache Hive is an excellent tool to retrieve data from HDFS  using SQL queries. I used Json Serde library to map Json files into Hive table. So initially I created table like this: CREATE EXTERNAL TABLE twitter ( coordinates struct , type:string, created_at string, entities struct , text:string, urls:array , url:string, user_mentions:array , name:string, screen_name:string, favorite_count int, favorited boolean, filter_level string, geo struct , type:string, id_str string, in_reply_to_screen_name string, in_reply_to_status_id_str string, in_reply_to_user_id_str string, lang string, retweet_count int, retweeted boolean, retweeted_status struct , text:string, urls:array , url:string;, user_mentions:array , name:string, screen_name:string, favorite_count:int, favorited:boolean, geo:struct , type:string, id_str:string, in_reply_to_screen_name:string, in_reply_to_status_id_str:string, in_reply_to_user_id_str:string, lang:string, retweet_count:int, retwe

Running Mahout K-Means example

   CDH4 comes with Mahout library by default. You don't need to install mahout unless if you want to upgrade to the latest version. Mahout is a scalable machine learning library which supports many algorithms for clustering, classification, topic modeling, prediction and recommendation systems. It can have terabytes of input data and process the clustering or classification in less than an hour depending on how powerful is your hadoop cluster. In my case I am using 4 powerful PCs with virtual nodes.    I had a task to model topics from twitter data for 2 months. I tried to run LDA(Latent Dirichlet Allocation - topic modeling algorithm) with R on one PC and it took several hours to build a document matrix of one day tweets(around 800,000) . And for improving results the number of topics K should be bigger than 500 thus exponentially increasing the LDA processing time. It is how I turned into Mahout.    Except Mahout there are other parallel machine learning libraries. Notable on

How I visualized the issues related to Sewol for 04.16 ~ 05.05

세월호 이슈 타임라인 from Hikmat on Vimeo . In April 16 there was a big tragedy in Korea, the ferry named Sewol (세월호) sank just in few hours causing the death of hundreds of students. After the tragedy, there were millions of tweets talking about sewol related issues. By analyzing these tweets we could see how people felt about sewol tragedy, how their opinions changed during the time, whom they blamed and how much they hoped for the survival of missing students.   We calculated  TF-IDF  values with Sewol keywords, and from those we selected the top issues related to this tragedy. We exported results to excel where the rows represented the date and time, and the columns represented the words.   I used 3ds max for visualization. It has MaxScript programming environment. I made a script to import the data from excel and draw the texts on 3D space, then animated their size by their TF-IDF value. The position of words are distributed randomly. Watch it and feel free to comment what you

Which device is famous for tweeting in Korea

I was wondering how many people use android to tweet and how many use iphone, so I did little bit a research on this, Fortunately, there is a "source" field in raw json tweet data, so I grouped tweets by that field for random day. hive>  select source, count(*) as cnt from twitter where datehour>=2014052000 and datehour<=2014052023 group by source order by cnt desc;   Result: Android 593671 Web 204334 Twittbot.net 153035 iPhone 144256 Tweetdeck 65767 iPad 19933 Note that the tweets are for May 20 including only the ones with korean syllables

NLP (Natural Language Processing) libraries for Korean language

There are mainly 2 available NLP libraries for Korean language. The first one is open source and the other is closed source with limited period of license. 1. Kookmin NLP library ( http://nlp.kookmin.ac.kr/ ) This library has better dictionary, and word spacing feature which gives a nice output. It has a very long development history and considered to be one the best NLP libraries for Korean language. Its features include: automatic word spacing, morphological analyzer, noun extraction and others. However, the license is free only for non-commercial purpose. The download page is in : http://nlp.kookmin.ac.kr/HAM/kor/download.html But the latest version you can find in this blog: http://cafe.daum.net/nlpk 2. Hannanum project (" http://kldp.net/projects/hannanum ") Good thing about this project is it is fully open-source. Developed by KAIST graduates using JAVA programming language. The dictionaries and grammatical rules are open to change and improve. Also it

Three essential things to do while building Hadoop environment

Last year I setup Hadoop environment by using Cloudera manager. (Basically I followed this video tutorial :  http://www.youtube.com/watch?v=CobVqNMiqww ) I used CDH4(cloudera hadoop)  that included HDFS, MapReduce, Hive, ZooKeeper HBase, Flume and other essential components. It also included YARN (MapReduce 2) but it was not stable so I used MapReduce instead. I installed CDH4 on 10 centos nodes, and I set the Flume to collect twitter data, and by using "crontab" I scheduled the indexing the twitter data in Hive. Anyways, I want to share some of my experiences  and challenges that I faced. First, let me give some problem solutions that everyone must had faced while using Hadoop. 1. vm.swappiness warning on hadoop nodes It is easy to get rid of this warning by just simply running this shell command on nodes: >sysctl -w vm.swappiness=0 More details are written on cloudera's site 2. Make sure to synchronize time on all nodes (otherwise it will give error on n