hadoop_java_sdk.md 22.4 KB
Newer Older
1 2
# Use JuiceFS Hadoop Java SDK

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
* [Hadoop Compatibility](#hadoop-compatibility)
* [Compiling](#compiling)
* [Deploy JuiceFS Hadoop Java SDK](#deploy-juicefs-hadoop-java-sdk)
  + [Hadoop Distribution](#hadoop-distribution)
  + [Community Components](#community-components)
* [Configurations](#configurations)
  + [Core Configurations](#core-configurations)
  + [Cache Configurations](#cache-configurations)
  + [I/O Configurations](#io-configurations)
  + [Other Configurations](#other-configurations)
  + [Configurations Example](#configurations-example)
  + [Configuration in Hadoop](#configuration-in-hadoop)
    - [CDH6](#cdh6)
    - [HDP](#hdp)
  + [Configuration in Flink](#configuration-in-flink)
* [Restart Services](#restart-services)
* [Verification](#verification)
  + [Hadoop](#hadoop)
  + [Hive](#hive)
* [Metrics](#metrics)
* [Benchmark](#benchmark)
  + [Local Benchmark](#local-benchmark)
  + [Distributed Benchmark](#distributed-benchmark)
* [FAQ](#faq)
S
Suave Su 已提交
27

28 29
JuiceFS provides [Hadoop-compatible FileSystem](https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/filesystem/introduction.html) by Hadoop Java SDK to support variety of components in Hadoop ecosystem.

30 31
> **NOTICE**:
>
32
> JuiceFS use local mapping of user and UID. So, you should [sync all the needed users and their UIDs](sync_accounts_between_multiple_hosts.md) across the whole Hadoop cluster to avoid permission error. You can also specify a global user list and user group file, please refer to the [relevant configurations](#other-configurations).
33 34
>
> JuiceFS Hadoop Java SDK need extra 4 * ``juicefs.memory-size`` off-heap memory at most. By default, up to 1.2 GB of additional memory is required (depends on write load).
35

36 37 38 39
## Hadoop Compatibility

JuiceFS Hadoop Java SDK is compatible with Hadoop 2.x and Hadoop 3.x. As well as variety of components in Hadoop ecosystem.

40 41 42
In order to make JuiceFS works with other components, it usually takes 2 steps:

1. Put JAR file into the classpath of each Hadoop ecosystem component.
43
2. Put JuiceFS configurations into the configuration file of each Hadoop ecosystem component (usually `core-site.xml`).
44

45 46 47 48 49 50 51 52 53
## Compiling

You need first installing Go 1.13+, JDK 8+ and Maven, then run following commands:

```shell
$ cd sdk/java
$ make
```

54 55
> **Tip**: For users in China, it's recommended to set a local Maven mirror to speed-up compilation, e.g. [Aliyun Maven Mirror](https://maven.aliyun.com).

56 57 58 59
## Deploy JuiceFS Hadoop Java SDK

After compiling you could find the JAR file in `sdk/java/target` directory, e.g. `juicefs-hadoop-0.10.0.jar`. Beware that file with `original-` prefix, it doesn't contain third-party dependencies. It's recommended to use the JAR file with third-party dependencies.

60
> **Note**: The SDK could only be deployed to same operating system as it be compiled. For example, if you compile SDK in Linux then you must deploy it to Linux.
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 101

Then put the JAR file and `$JAVA_HOME/lib/tools.jar` to the classpath of each Hadoop ecosystem component. It's recommended create a symbolic link to the JAR file. The following tables describe where the SDK be placed.

### Hadoop Distribution

| Name              | Installing Paths                                                                                                                                                                                                                                                                                                           |
| ----              | ----------------                                                                                                                                                                                                                                                                                                           |
| CDH               | `/opt/cloudera/parcels/CDH/lib/hadoop/lib`<br>`/opt/cloudera/parcels/CDH/spark/jars`<br>`/var/lib/impala`                                                                                                                                                                                                                  |
| HDP               | `/usr/hdp/current/hadoop-client/lib`<br>`/usr/hdp/current/hive-client/auxlib`<br>`/usr/hdp/current/spark2-client/jars`                                                                                                                                                                                                     |
| Amazon EMR        | `/usr/lib/hadoop/lib`<br>`/usr/lib/spark/jars`<br>`/usr/lib/hive/auxlib`                                                                                                                                                                                                                                                   |
| Alibaba Cloud EMR | `/opt/apps/ecm/service/hadoop/*/package/hadoop*/share/hadoop/common/lib`<br>`/opt/apps/ecm/service/spark/*/package/spark*/jars`<br>`/opt/apps/ecm/service/presto/*/package/presto*/plugin/hive-hadoop2`<br>`/opt/apps/ecm/service/hive/*/package/apache-hive*/lib`<br>`/opt/apps/ecm/service/impala/*/package/impala*/lib` |
| Tencent Cloud EMR | `/usr/local/service/hadoop/share/hadoop/common/lib`<br>`/usr/local/service/presto/plugin/hive-hadoop2`<br>`/usr/local/service/spark/jars`<br>`/usr/local/service/hive/auxlib`                                                                                                                                              |
| UCloud UHadoop    | `/home/hadoop/share/hadoop/common/lib`<br>`/home/hadoop/hive/auxlib`<br>`/home/hadoop/spark/jars`<br>`/home/hadoop/presto/plugin/hive-hadoop2`                                                                                                                                                                             |
| Baidu Cloud EMR   | `/opt/bmr/hadoop/share/hadoop/common/lib`<br>`/opt/bmr/hive/auxlib`<br>`/opt/bmr/spark2/jars`                                                                                                                                                                                                                              |

### Community Components

| Name   | Installing Paths                     |
| ----   | ----------------                     |
| Spark  | `${SPARK_HOME}/jars`                 |
| Presto | `${PRESTO_HOME}/plugin/hive-hadoop2` |
| Flink  | `${FLINK_HOME}/lib`                  |

## Configurations

### Core Configurations

| Configuration                    | Default Value                | Description                                                                                                                                               |
| -------------                    | -------------                | -----------                                                                                                                                               |
| `fs.jfs.impl`                    | `io.juicefs.JuiceFileSystem` | The FileSystem implementation for `jfs://` URIs. If you wanna use different schema (e.g. `cfs://`), you could rename this configuration to `fs.cfs.impl`. |
| `fs.AbstractFileSystem.jfs.impl` | `io.juicefs.JuiceFS`         |                                                                                                                                                           |
| `juicefs.meta`                   |                              | Redis URL. Its format is `redis://<user>:<password>@<host>:<port>/<db>`.                                                                                  |
| `juicefs.accesskey`              |                              | Access key of object storage. See [this document](how_to_setup_object_storage.md) to learn how to get access key for different object storage.            |
| `juicefs.secretkey`              |                              | Secret key of object storage. See [this document](how_to_setup_object_storage.md) to learn how to get secret key for different object storage.            |

### Cache Configurations

| Configuration                | Default Value | Description                                                                                                                                                                                                                                                                                           |
| -------------                | ------------- | -----------                                                                                                                                                                                                                                                                                           |
| `juicefs.cache-dir`          |               | Directory paths of local cache. Use colon to separate multiple paths. Also support wildcard in path. **It's recommended create these directories manually and set `0777` permission so that different applications could share the cache data.**                                                      |
| `juicefs.cache-size`         | 0             | Maximum size of local cache in MiB. It's the total size when set multiple cache directories.                                                                                                                                                                                                          |
102
| `juicefs.cache-full-block`   | `true`        | Whether cache every read blocks, `false` means only cache random/small read blocks.                                                                                                                                                                                                                   |
103
| `juicefs.free-space`         | 0.1           | Min free space ratio of cache directory                                                                                                                                                                                                                                                               |
104 105
| `juicefs.discover-nodes-url` |               | The URL to discover cluster nodes, refresh every 10 minutes.<br /><br />YARN: `yarn`<br />Spark Standalone: `http://spark-master:web-ui-port/json/`<br />Spark ThriftServer: `http://thrift-server:4040/api/v1/applications/`<br />Presto: `http://coordinator:discovery-uri-port/v1/service/presto/` |

106 107
### I/O Configurations

108 109 110 111 112 113 114 115 116
| Configuration            | Default Value | Description                                     |
| -------------            | ------------- | -----------                                     |
| `juicefs.max-uploads`    | 20            | The max number of connections to upload         |
| `juicefs.get-timeout`    | 5             | The max number of seconds to download an object |
| `juicefs.put-timeout`    | 60            | The max number of seconds to upload an object   |
| `juicefs.memory-size`    | 300           | Total read/write buffering in MiB               |
| `juicefs.prefetch`       | 1             | Prefetch N blocks in parallel                   |
| `juicefs.upload-limit`   | 0             | Bandwidth limit for upload in Mbps              |
| `juicefs.download-limit` | 0             | Bandwidth limit for download in Mbps            |
117

118 119
### Other Configurations

120 121 122 123 124
| Configuration             | Default Value | Description                                                                                                                                                                 |
| -------------             | ------------- | -----------                                                                                                                                                                 |
| `juicefs.debug`           | `false`       | Whether enable debug log                                                                                                                                                    |
| `juicefs.access-log`      |               | Access log path. Ensure Hadoop application has write permission, e.g. `/tmp/juicefs.access.log`. The log file will rotate  automatically to keep at most 7 files.           |
| `juicefs.superuser`       | `hdfs`        | The super user                                                                                                                                                              |
T
tangyoupeng 已提交
125 126
| `juicefs.users`           | `null`        | The path of username and UID list file, e.g. `jfs://name/etc/users`. The file format is `<username>:<UID>`, one user per line.                                              |
| `juicefs.groups`          | `null`        | The path of group name, GID and group members list file, e.g. `jfs://name/etc/groups`. The file format is `<group-name>:<GID>:<username1>,<username2>`, one group per line. |
127 128 129 130 131 132
| `juicefs.umask`           | `null`        | The umask used when creating files and directories (e.g. `0022`), default value is `fs.permissions.umask-mode`.                                                             |
| `juicefs.push-gateway`    |               | [Prometheus Pushgateway](https://github.com/prometheus/pushgateway) address, format is `<host>:<port>`.                                                                     |
| `juicefs.push-interval`   | 10            | Prometheus push interval in seconds                                                                                                                                         |
| `juicefs.push-auth`       |               | [Prometheus basic auth](https://prometheus.io/docs/guides/basic-auth) information, format is `<username>:<password>`.                                                       |
| `juicefs.fast-resolve`    | `true`        | Whether enable faster metadata lookup using Redis Lua script                                                                                                                |
| `juicefs.no-usage-report` | `false`       | Whether disable usage reporting. JuiceFS only collects anonymous usage data (e.g. version number), no user or any sensitive data will be collected.                         |
133 134 135 136 137 138 139 140 141 142 143 144

When you use multiple JuiceFS file systems, all these configurations could be set to specific file system alone. You need put file system name in the middle of configuration, for example (replace `{JFS_NAME}` with appropriate value):

```xml
<property>
  <name>juicefs.{JFS_NAME}.meta</name>
  <value>redis://host:port/1</value>
</property>
```

### Configurations Example

145
> **Note**: Replace `{HOST}`, `{PORT}` and `{DB}` in `juicefs.meta` with appropriate values.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

```xml
<property>
  <name>fs.jfs.impl</name>
  <value>io.juicefs.JuiceFileSystem</value>
</property>
<property>
  <name>fs.AbstractFileSystem.jfs.impl</name>
  <value>io.juicefs.JuiceFS</value>
</property>
<property>
  <name>juicefs.meta</name>
  <value>redis://{HOST}:{PORT}/{DB}</value>
</property>
<property>
  <name>juicefs.cache-dir</name>
  <value>/data*/jfs</value>
</property>
<property>
  <name>juicefs.cache-size</name>
  <value>1024</value>
</property>
<property>
  <name>juicefs.access-log</name>
  <value>/tmp/juicefs.access.log</value>
</property>
```

### Configuration in Hadoop

Add configurations to `core-site.xml`.

S
Suave Su 已提交
178
#### CDH6
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

Besides `core-site`, you also need to configure `mapreduce.application.classpath` of the YARN component, add:

```shell
$HADOOP_COMMON_HOME/lib/juicefs-hadoop.jar
```

#### HDP

Besides `core-site`, you also need to configure `mapreduce.application.classpath` of the MapReduce2 component, add (variables do not need to be replaced):

```shell
/usr/hdp/${hdp.version}/hadoop/lib/juicefs-hadoop.jar
```

194 195 196 197
### Configuration in Flink

Add configurations to `conf/flink-conf.yaml`. You could only setup Flink client without modify configurations in Hadoop.

198 199
## Restart Services

200
When the following components need to access JuiceFS, they should be restarted.
201

202
> **Note**: Before restart, you need to confirm JuiceFS related configuration has been written to the configuration file of each component, usually you can find them in `core-site.xml` on the machine where the service of the component was deployed.
203

204 205 206 207 208 209 210
| Components | Services                   |
| ---------- | --------                   |
| Hive       | HiveServer<br />Metastore  |
| Spark      | ThriftServer               |
| Presto     | Coordinator<br />Worker    |
| Impala     | Catalog Server<br />Daemon |
| HBase      | Master<br />RegionServer   |
211

212
HDFS, Hue, ZooKeeper and other services don't need to be restarted.
213

214
When `Class io.juicefs.JuiceFileSystem not found` or `No FilesSystem for scheme: jfs` exceptions was occurred after restart, reference [FAQ](#faq).
215

216 217 218 219 220 221 222 223
## Verification

### Hadoop

```bash
$ hadoop fs -ls jfs://{JFS_NAME}/
```

224 225
> **Note**: The `JFS_NAME` is the volume name when you format JuiceFS file system.

226 227 228 229 230 231 232 233 234
### Hive

```sql
CREATE TABLE IF NOT EXISTS person
(
  name STRING,
  age INT
) LOCATION 'jfs://{JFS_NAME}/tmp/person';
```
235

236 237
## Metrics

238
JuiceFS Hadoop Java SDK supports reporting metrics to [Prometheus Pushgateway](https://github.com/prometheus/pushgateway), then you can use [Grafana](https://grafana.com) and [dashboard template](grafana_template.json) to visualize these metrics.
239 240 241 242 243 244 245 246 247 248 249

Enable metrics reporting through following configurations:

```xml
<property>
  <name>juicefs.push-gateway</name>
  <value>host:port</value>
</property>
```

> **Note**: Each process using JuiceFS Hadoop Java SDK will have a unique metric, and Pushgateway will always remember all the collected metrics, resulting in the continuous accumulation of metrics and taking up too much memory, which will also slow down Prometheus crawling metrics. It is recommended to clean up metrics which `job` is `juicefs` on Pushgateway regularly. It is recommended to use the following command to clean up once every hour. The running Hadoop Java SDK will continue to update after the metrics are cleared, which basically does not affect the use.
250 251 252 253
>
> ```bash
> $ curl -X DELETE http://host:9091/metrics/job/juicefs
> ```
254

255
For a description of all monitoring metrics, please refer to [JuiceFS Metrics](p8s_metrics.md).
256

257 258 259 260
## Benchmark

JuiceFS provides some benchmark tools for you when JuiceFS has been deployed

261
### Local Benchmark
262 263 264 265 266
#### Meta

- create

  ```shell
T
tangyoupeng 已提交
267
  hadoop jar juicefs-hadoop.jar nnbench create -files 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench -local
268 269 270 271 272 273 274
  ```

  It creates 10000 empty files without write data

- open

  ```shell
T
tangyoupeng 已提交
275
  hadoop jar juicefs-hadoop.jar nnbench open -files 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench -local
276 277 278 279 280 281 282
  ```

  It opens 10000 files without read data

- rename

  ```shell
T
tangyoupeng 已提交
283
  hadoop jar juicefs-hadoop.jar nnbench rename -files 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench -local
284 285 286 287 288
  ```

- delete

  ```shell
T
tangyoupeng 已提交
289
  hadoop jar juicefs-hadoop.jar nnbench delete -files 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench -local
290 291 292 293
  ```

- for reference

294 295
| Operation | TPS  | Delay (ms) |
| --------- | ---  | ---------- |
T
tangyoupeng 已提交
296 297 298 299
| create | 644  | 1.55       |
| open   | 3467 | 0.29       |
| rename | 483  | 2.07       |
| delete | 506  | 1.97       |
300

S
Suave Su 已提交
301
#### I/O Performance
302 303 304 305

- sequential write

  ```shell
T
tangyoupeng 已提交
306
  hadoop jar juicefs-hadoop.jar dfsio -write -size 20000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/DFSIO -local
307 308 309 310 311
  ```

- sequential read

  ```shell
T
tangyoupeng 已提交
312
  hadoop jar juicefs-hadoop.jar dfsio -read -size 20000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/DFSIO -local
313 314 315 316 317 318
  ```

  When run the cmd for the second time, the result may be much better than the first run. It's because the data was cached in memory, just clean the local disk cache.

- for reference

319 320
| Operation | Throughput (MB/s) |
| --------- | ----------------- |
T
tangyoupeng 已提交
321 322
| write  | 647          |
| read   | 111          |
323

324
### Distributed Benchmark
325

326
Distributed benchmark use MapReduce program to test meta and IO throughput performance
327 328 329

Enough resources should be provided to make sure all Map task can be started at the same time

330
We use 3 4c32g ECS (5Gbit/s) and Aliyun Redis 5.0 4G redis for the benchmark
331 332 333 334 335 336

#### Meta

- create

  ```shell
T
tangyoupeng 已提交
337
  hadoop jar juicefs-hadoop.jar nnbench create -maps 10 -threads 10 -files 1000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench
338 339 340 341
  ```

  10 map task, each has 10 threads, each thread create 1000 empty file. 100000 files in total

T
tangyoupeng 已提交
342
- open
343 344

  ```shell
T
tangyoupeng 已提交
345
  hadoop jar juicefs-hadoop.jar nnbench open -maps 10 -threads 10 -files 1000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench
346 347 348
  ```

  10 map task, each has 10 threads, each thread open 1000 file. 100000 files in total
349

T
tangyoupeng 已提交
350
- rename
351 352

  ```shell
T
tangyoupeng 已提交
353
  hadoop jar juicefs-hadoop.jar nnbench rename -maps 10 -threads 10 -files 1000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench
354 355 356 357 358
  ```

  10 map task, each has 10 threads, each thread rename 1000 file. 100000 files in total


T
tangyoupeng 已提交
359
- delete
360 361

  ```shell
T
tangyoupeng 已提交
362
  hadoop jar juicefs-hadoop.jar nnbench delete -maps 10 -threads 10 -files 1000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/NNBench
363 364 365
  ```

  10 map task, each has 10 threads, each thread delete 1000 file. 100000 files in total
366

367 368 369 370
- for reference

    - 10 threads

371 372
  | Operation | TPS  | Delay (ms) |
  | --------- | ---  | ---------- |
T
tangyoupeng 已提交
373 374 375 376
  | create | 4178 | 2.2        |
  | open   | 9407 | 0.8        |
  | rename | 3197 | 2.9       |
  | delete | 3060 | 3.0        |
377 378 379

    - 100 threads

380 381
  | Operation | TPS   | Delay (ms) |
  | --------- | ---   | ---------- |
T
tangyoupeng 已提交
382 383 384 385
  | create | 11773  | 7.9       |
  | open   | 34083 | 2.4        |
  | rename | 8995  | 10.8       |
  | delete | 7191  | 13.6       |
386

S
Suave Su 已提交
387
#### I/O Performance
388 389 390 391

- sequential write

  ```shell
T
tangyoupeng 已提交
392
  hadoop jar juicefs-hadoop.jar dfsio -write -maps 10 -size 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/DFSIO
393 394 395 396 397 398 399
  ```

  10 map task, each task write 10000MB random data sequentially

- sequential read

  ```shell
T
tangyoupeng 已提交
400
  hadoop jar juicefs-hadoop.jar dfsio -read -maps 10 -size 10000 -baseDir jfs://{JFS_NAME}/tmp/benchmarks/DFSIO
401 402 403 404 405 406 407
  ```

  10 map task, each task read 10000MB random data sequentially


- for reference

408 409
| Operation | Total Throughput (MB/s) |
| --------- | ----------------------- |
T
tangyoupeng 已提交
410 411
| write     | 1835                    |
| read      | 1234                    |
412 413


414 415 416 417
## FAQ

### `Class io.juicefs.JuiceFileSystem not found` exception

418
It means JAR file was not loaded, you can verify it by `lsof -p {pid} | grep juicefs`.
419

420
You should check whether the JAR file was located properly, or other users have the read permission.
421

422
Some Hadoop distribution also need to modify `mapred-site.xml` and put the JAR file location path to the end of the parameter `mapreduce.application.classpath`.
423 424 425

### `No FilesSystem for scheme: jfs` exception

426
It means JuiceFS Hadoop Java SDK was not configured properly, you need to check whether there is JuiceFS related configuration in the `core-site.xml` of the component configuration.