NativeLibraries.md.vm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!---
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. See accompanying LICENSE file.
  11. -->
  12. Native Libraries Guide
  13. ======================
  14. <!-- MACRO{toc|fromDepth=0|toDepth=3} -->
  15. Overview
  16. --------
  17. This guide describes the native hadoop library and includes a small discussion about native shared libraries.
  18. Note: Depending on your environment, the term "native libraries" could refer to all \*.so's you need to compile; and, the term "native compression" could refer to all \*.so's you need to compile that are specifically related to compression. Currently, however, this document only addresses the native hadoop library (`libhadoop.so`). The document for libhdfs library (`libhdfs.so`) is [here](../hadoop-hdfs/LibHdfs.html).
  19. Native Hadoop Library
  20. ---------------------
  21. Hadoop has native implementations of certain components for performance reasons and for non-availability of Java implementations. These components are available in a single, dynamically-linked native library called the native hadoop library. On the \*nix platforms the library is named `libhadoop.so`.
  22. Usage
  23. -----
  24. It is fairly easy to use the native hadoop library:
  25. 1. Review the components.
  26. 2. Review the supported platforms.
  27. 3. Either download a hadoop release, which will include a pre-built version of the native hadoop library, or build your own version of the native hadoop library. Whether you download or build, the name for the library is the same: libhadoop.so
  28. 4. Install the compression codec development packages (\>zlib-1.2, \>gzip-1.2):
  29. * If you download the library, install one or more development packages - whichever compression codecs you want to use with your deployment.
  30. * If you build the library, it is mandatory to install both development packages.
  31. 5. Check the runtime log files.
  32. Components
  33. ----------
  34. The native hadoop library includes various components:
  35. * Compression Codecs (bzip2, lz4, snappy, zlib)
  36. * Native IO utilities for [HDFS Short-Circuit Local Reads](../hadoop-hdfs/ShortCircuitLocalReads.html) and [Centralized Cache Management in HDFS](../hadoop-hdfs/CentralizedCacheManagement.html)
  37. * CRC32 checksum implementation
  38. Supported Platforms
  39. -------------------
  40. The native hadoop library is supported on \*nix platforms only. The library does not to work with Cygwin or the Mac OS X platform.
  41. The native hadoop library is mainly used on the GNU/Linus platform and has been tested on these distributions:
  42. * RHEL4/Fedora
  43. * Ubuntu
  44. * Gentoo
  45. On all the above distributions a 32/64 bit native hadoop library will work with a respective 32/64 bit jvm.
  46. Download
  47. --------
  48. The pre-built 32-bit i386-Linux native hadoop library is available as part of the hadoop distribution and is located in the `lib/native` directory. You can download the hadoop distribution from Hadoop Common Releases.
  49. Be sure to install the zlib and/or gzip development packages - whichever compression codecs you want to use with your deployment.
  50. Build
  51. -----
  52. The native hadoop library is written in ANSI C and is built using the GNU autotools-chain (autoconf, autoheader, automake, autoscan, libtool). This means it should be straight-forward to build the library on any platform with a standards-compliant C compiler and the GNU autotools-chain (see the supported platforms).
  53. The packages you need to install on the target platform are:
  54. * C compiler (e.g. GNU C Compiler)
  55. * GNU Autools Chain: autoconf, automake, libtool
  56. * zlib-development package (stable version \>= 1.2.0)
  57. * openssl-development package(e.g. libssl-dev)
  58. Once you installed the prerequisite packages use the standard hadoop pom.xml file and pass along the native flag to build the native hadoop library:
  59. $ mvn package -Pdist,native -DskipTests -Dtar
  60. You should see the newly-built library in:
  61. $ hadoop-dist/target/hadoop-${project.version}/lib/native
  62. Please note the following:
  63. * It is mandatory to install both the zlib and gzip development packages on the target platform in order to build the native hadoop library; however, for deployment it is sufficient to install just one package if you wish to use only one codec.
  64. * It is necessary to have the correct 32/64 libraries for zlib, depending on the 32/64 bit jvm for the target platform, in order to build and deploy the native hadoop library.
  65. Runtime
  66. -------
  67. The bin/hadoop script ensures that the native hadoop library is on the library path via the system property: `-Djava.library.path=<path> `
  68. During runtime, check the hadoop log files for your MapReduce tasks.
  69. * If everything is all right, then: `DEBUG util.NativeCodeLoader - Trying to load the custom-built native-hadoop library...` `INFO util.NativeCodeLoader - Loaded the native-hadoop library`
  70. * If something goes wrong, then: `INFO util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable`
  71. Check
  72. -----
  73. NativeLibraryChecker is a tool to check whether native libraries are loaded correctly. You can launch NativeLibraryChecker as follows:
  74. $ hadoop checknative -a
  75. 14/12/06 01:30:45 WARN bzip2.Bzip2Factory: Failed to load/initialize native-bzip2 library system-native, will use pure-Java version
  76. 14/12/06 01:30:45 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
  77. Native library checking:
  78. hadoop: true /home/ozawa/hadoop/lib/native/libhadoop.so.1.0.0
  79. zlib: true /lib/x86_64-linux-gnu/libz.so.1
  80. snappy: true /usr/lib/libsnappy.so.1
  81. lz4: true revision:99
  82. bzip2: false
  83. Native Shared Libraries
  84. -----------------------
  85. You can load any native shared library using DistributedCache for distributing and symlinking the library files.
  86. This example shows you how to distribute a shared library, mylib.so, and load it from a MapReduce task.
  87. 1. First copy the library to the HDFS: `bin/hadoop fs -copyFromLocal mylib.so.1 /libraries/mylib.so.1`
  88. 2. The job launching program should contain the following: `DistributedCache.createSymlink(conf);` `DistributedCache.addCacheFile("hdfs://host:port/libraries/mylib.so. 1#mylib.so", conf);`
  89. 3. The MapReduce task can contain: `System.loadLibrary("mylib.so");`
  90. Note: If you downloaded or built the native hadoop library, you don’t need to use DistibutedCache to make the library available to your MapReduce tasks.