热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ALLuxio

一、什么是AlluxioAlluxio(之前名为Tachyon)是世界上第一个以内存为中心的虚拟的分布式存储系统。它统一了数据访问的方式,

一、什么是Alluxio
Alluxio(之前名为Tachyon)是世界上第一个以内存为中心的虚拟的分布式存储系统。它统一了数据访问的方式,为上层计算框架和底层存储系统构建了桥梁。应用只需要连接Alluxio即可访问存储在底层任意存储系统中的数据。此外,Alluxio的以内存为中心的架构使得数据的访问速度能比现有常规方案快几个数量级。

在大数据生态系统中,Alluxio介于计算框架(如Apache Spark,Apache MapReduce,Apache HBase,Apache Hive,Apache Flink)和现有的存储系统(如Amazon S3,OpenStack Swift,GlusterFS,HDFS,MaprFS,Ceph,NFS,OSS)之间。Alluxio为大数据软件栈带来了显著的性能提升。Alluxio与Hadoop是兼容的。现有的数据分析应用,如Spark和MapReduce程序,可以不修改代码直接在Alluxio上运行。

二、Alluxio应用
比如:分布式内存文件系统Alluxio, Alluxio是一个分布式内存文件系统,可以在集群里以访问内存的速度来访问存在Alluxio里的文件。把Alluxio是架构在最底层的分布式文件存储和上层的各种计算框架之间的一种中间件,其前身为Tachyon。

二、安装Alluxio
docker安装

# Launch the Alluxio master
$ docker run -d \-p 19999:19999 \--net=alluxio_nw \--name=alluxio_master \-v ufs:/opt/alluxio/underFSStorage \alluxio/alluxio master
# Launch the Alluxio worker
$ docker run -d \--net=alluxio_nw \--name=alluxio_worker \--shm-size=1G -e ALLUXIO_WORKER_MEMORY_SIZE=1G \-v ufs:/opt/alluxio/underFSStorage \-e ALLUXIO_MASTER_HOSTNAME=alluxio_master \alluxio/alluxio worker

三、Alluxio与springboot应用

依赖 pom.xml


4.0.0org.springframework.bootspring-boot-starter-parent2.1.5.RELEASE com.citydoalluxio0.0.1-SNAPSHOTalluxioDemo project for Spring Boot1.8org.springframework.bootspring-boot-starter-weborg.alluxioalluxio-core-client-fs1.8.1org.springframework.bootspring-boot-starter-testtestcom.alibaba.blinkflink-shaded-hadoop21.5.1org.springframework.bootspring-boot-maven-plugin

控制层 controller

package com.citydo.alluxio.controller;import alluxio.AlluxioURI;
import alluxio.client.file.FileInStream;
import alluxio.client.file.FileOutStream;
import alluxio.client.file.FileSystem;
import alluxio.exception.AlluxioException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.io.IOException;@RestController
@RequestMapping("/v1/alluxio")
public class AlluxioController {@RequestMapping("/in")public FileInStream in() throws IOException, AlluxioException {FileSystem fs = FileSystem.Factory.get();AlluxioURI path = new AlluxioURI("/myFile");// Open the file for readingFileInStream in = fs.openFile(path);//CreateFileOptions options = CreateFileOptions.defaults().setBlockSize(128 * Constants.MB);//FileOutStream out = fs.createFile(path, options);// Read datain.read(null);// Close file relinquishing the lockin.close();return in;}@RequestMapping("/out")public FileOutStream out() throws IOException, AlluxioException {FileSystem fs = FileSystem.Factory.get();AlluxioURI path = new AlluxioURI("/myFile");// Create a file and get its output streamFileOutStream out = fs.createFile(path);// Write dataout.write(null);// Close and complete fileout.close();return out;}//参考https://docs.alluxio.io/os/javadoc/stable/index.html
}

工具类 AlluxioFsUitls

package com.citydo.alluxio.utils;import alluxio.AlluxioURI;
import alluxio.client.ReadType;
import alluxio.client.WriteType;
import alluxio.client.file.FileSystem;
import alluxio.client.file.URIStatus;
import alluxio.client.file.options.CreateFileOptions;
import alluxio.client.file.options.OpenFileOptions;
import alluxio.exception.AlluxioException;import java.io.*;
import java.util.ArrayList;
import java.util.List;public class AlluxioFsUitls {// 获取文件系统FileSystemprivate static final FileSystem fs = FileSystem.Factory.get();/*** 此方法用于添加挂载点** @param alluxioFilePath* 文件路径*/public static void mount(String alluxioFilePath, String underFileSystemPath) {// 1.创建文件路径 AlluxioURIAlluxioURI apath = new AlluxioURI(alluxioFilePath);AlluxioURI upath = new AlluxioURI(underFileSystemPath);try {// 2.添加挂载点if (!fs.exists(apath)) {fs.mount(apath, upath);}} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}}/*** 此方法用于删除挂载点** @param filePath* 文件路径*/public static void unmount(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.删除挂载点if (fs.exists(path)) {fs.unmount(path);}} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}}/*** 此方法用于创建文件,并向文件中输出内容WriteType.ASYNC_THROUGH* 数据被同步地写入到Alluxio的Worker,并异步地写入到底层存储系统。处于实验阶段。** @param filePath* 文件路径* @param contents* 向文件中输出的内容* @return 文件创建,是否成功*/public static boolean createFileMustAsysncThroughWriteTpye(String filePath, List contents) {return createFile(filePath, contents, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH));}/*** 此方法用于创建文件,并向文件中输出内容WriteType.CACHE_THROUGH* 数据被同步地写入到Alluxio的Worker和底层存储系统。** @param filePath* 文件路径* @param contents* 向文件中输出的内容* @return 文件创建,是否成功*/public static boolean createFileMustCacheThroughWriteTpye(String filePath, List contents) {return createFile(filePath, contents, CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH));}/*** 此方法用于创建文件,并向文件中输出内容WriteType.THROUGH* 数据被同步地写入到底层存储系统。但不会被写入到Alluxio的Worker。** @param filePath* 文件路径* @param contents* 向文件中输出的内容* @return 文件创建,是否成功*/public static boolean createFileMustThroughWriteTpye(String filePath, List contents) {return createFile(filePath, contents, CreateFileOptions.defaults().setWriteType(WriteType.THROUGH));}/*** 此方法用于创建文件,并向文件中输出内容WriteType.MUST_CACHE* 数据被同步地写入到Alluxio的Worker。但不会被写入到底层存储系统。这是默认写类型。** @param filePath* 文件路径* @param contents* 向文件中输出的内容* @return 文件创建,是否成功*/public static boolean createFileMustCacheWriteTpye(String filePath, List contents) {return createFile(filePath, contents, CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE));}/*** 方法用于创建文件,并向文件中输出内容** @param filePath* 文件路径* @param contents* 向文件中输出的内容* @param options* CreateFileOptions* @return 文件创建,是否成功*/public static boolean createFile(String filePath, List contents, CreateFileOptions options) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);BufferedWriter writer = null;try {// 2.打开文件输出流,使用BufferedWriter输出if (!fs.exists(path)) {writer = new BufferedWriter(new OutputStreamWriter(fs.createFile(path, options)));// 3.输出文件内容for (String line : contents) {writer.write(line);writer.newLine();}}// 3.如果文件存在,则表示执行成功return fs.exists(path);} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();} finally {try {// 4.关闭输入流,释放资源if (writer != null) {writer.close();}} catch (IOException e) {e.printStackTrace();}}return false;}/*** 此方法用于读取alluxio文件ReadType.CACHE_PROMOTE* 如果读取的数据在Worker上时,该数据被移动到Worker的最高层。如果该数据不在本地Worker的Alluxio存储中,* 那么就将一个副本添加到本地Alluxio Worker中,用于每次完整地读取数据块。这是默认的读类型。** @param filePath* 文件路径* @return 文件的内容*/public static List openFilePromoteCacheReadType(String filePath) {return openFile(filePath, OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE));}/*** 此方法用于读取alluxio文件ReadType.NO_CACHE 不会创建副本** @param filePath* 文件路径* @return 文件的内容*/public static List openFileNoCacheReadType(String filePath) {return openFile(filePath, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE));}/*** 此方法用于读取alluxio文件ReadType.CACHE* 如果该数据不在本地Worker的Alluxio存储中,那么就将一个副本添加到本地Alluxio Worker中, 用于每次完整地读取数据块。** @param filePath* 文件路径* @return 文件的内容*/public static List openFileCacheReadType(String filePath) {return openFile(filePath, OpenFileOptions.defaults().setReadType(ReadType.CACHE));}/*** 此方法用于读取alluxio文件DefalutReadType** @param filePath* 文件路径* @return 文件的内容*/public static List openFileDefalutReadType(String filePath) {return openFile(filePath, OpenFileOptions.defaults());}/*** 此方法用于读取alluxio文件** @param filePath* 文件路径* @param options* 文件读取选项* @return 文件的内容*/public static List openFile(String filePath, OpenFileOptions options) {List list = new ArrayList();// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);BufferedReader reader = null;try {// 2.打开文件输入流,使用 BufferedReader按行读取if (fs.exists(path)) {reader = new BufferedReader(new InputStreamReader(fs.openFile(path, options)));for (String line = null; (line = reader.readLine()) != null;) {list.add(line);}return list;}} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();} finally {try {// 3.关闭输入流,释放资源if (reader != null) {reader.close();}} catch (IOException e) {e.printStackTrace();}}return list;}/*** 此方法用于释放alluxio中的文件或路径** @param filePath* 文件路径* @return 释放文件, 是否成功*/public static boolean free(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.释放文件if (fs.exists(path)) {fs.free(path);}// 3.判定文件是否不存在,如果不存在则删除成功!return !fs.exists(path);} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return false;}/*** 此方法用于删除文件或路径** @param filePath* 文件路径* @return 删除文件, 是否成功*/public static boolean delete(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.删除文件if (fs.exists(path)) {fs.delete(path);}// 3.判定文件是否不存在,如果不存在则删除成功!return !fs.exists(path);} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return false;}/*** 此方法用于创建文件夹** @param dirPath* 文件夹路径* @return 创建文件夹, 是否成功*/public static boolean createDirectory(String dirPath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(dirPath);try {// 2.创建文件夹if (!fs.exists(path)) {fs.createDirectory(path);}// 3.再次判定文件夹是否存在,来确定文件夹是否创建成功return fs.exists(path);} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return false;}/*** 此方法用于获取文件状态信息** @param filePath* 文件路径* @return List*/public static List listStatus(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.获取文件状态信息if (fs.exists(path)) {return fs.listStatus(path);}} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return null;}/*** 此方法用于获取文件状态信息** @param filePath* 文件路径* @return URIStatus*/public static URIStatus getStatus(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.获取文件状态信息if (fs.exists(path)) {return fs.getStatus(path);}} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return null;}/*** 此方法用于判定文件是否存在** @param filePath* 文件路径* @return 文件是否存在*/public static boolean exists(String filePath) {// 1.创建文件路径 AlluxioURIAlluxioURI path = new AlluxioURI(filePath);try {// 2.获取文件状态信息return fs.exists(path);} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return false;}/*** 此方法用于重命名文件** @param sourcePath* 原文件路径* @param distPath* 目的文件路径* @return 重命名是否成功*/public static boolean rename(String sourcePath, String distPath) {// 1.创建文件路径 AlluxioURIAlluxioURI sourcepath = new AlluxioURI(sourcePath);AlluxioURI distpath = new AlluxioURI(distPath);try {// 2.重命名操作if (fs.exists(sourcepath)) {fs.rename(sourcepath, distpath);}// 3.判定目标文件是否存在,来判定重命名是否成功return ((fs.exists(distpath)) && (!fs.exists(sourcepath)));} catch (IOException e) {e.printStackTrace();} catch (AlluxioException e) {e.printStackTrace();}return false;}
}

四、性能对比
万级表
1.2G (2千万)


presto sqlHDFS(s)Alluxio(s)
count52
distinct + where3~101
group by21

亿级表
tableB 900G (45亿)


presto sqlHDFS(s)Alluxio(s)
count23~6911~14
distinct + where50~9520~21
group by76~15777~90

参考:https://www.alluxio.io/download/
参考:https://blog.csdn.net/lsshlsw/article/details/85690841
参考:https://docs.alluxio.io/os/user/stable/cn/Getting-Started.html


推荐阅读
  • Hadoop源码解析1Hadoop工程包架构解析
    1 Hadoop中各工程包依赖简述   Google的核心竞争技术是它的计算平台。Google的大牛们用了下面5篇文章,介绍了它们的计算设施。   GoogleCluster:ht ... [详细]
  • 一、Hadoop来历Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明 ... [详细]
  • ZooKeeper 学习
    前言相信大家对ZooKeeper应该不算陌生。但是你真的了解ZooKeeper是个什么东西吗?如果别人面试官让你给他讲讲ZooKeeper是个什么东西, ... [详细]
  •        在搭建Hadoop环境之前,请先阅读如下博文,把搭建Hadoop环境之前的准备工作做好,博文如下:       1、CentOS6.7下安装JDK,地址:http:b ... [详细]
  • 我们在之前的文章中已经初步介绍了Cloudera。hadoop基础----hadoop实战(零)-----hadoop的平台版本选择从版本选择这篇文章中我们了解到除了hadoop官方版本外很多 ... [详细]
  • 本文介绍了OpenStack的逻辑概念以及其构成简介,包括了软件开源项目、基础设施资源管理平台、三大核心组件等内容。同时还介绍了Horizon(UI模块)等相关信息。 ... [详细]
  • 本文总结了初学者在使用dubbo设计架构过程中遇到的问题,并提供了相应的解决方法。问题包括传输字节流限制、分布式事务、序列化、多点部署、zk端口冲突、服务失败请求3次机制以及启动时检查。通过解决这些问题,初学者能够更好地理解和应用dubbo设计架构。 ... [详细]
  • Hadoop2.6.0 + 云centos +伪分布式只谈部署
    3.0.3玩不好,现将2.6.0tar.gz上传到usr,chmod-Rhadoop:hadophadoop-2.6.0,rm掉3.0.32.在etcp ... [详细]
  • 什么是大数据lambda架构
    一、什么是Lambda架构Lambda架构由Storm的作者[NathanMarz]提出,根据维基百科的定义,Lambda架构的设计是为了在处理大规模数 ... [详细]
  • mapreduce源码分析总结
    这篇文章总结的非常到位,故而转之一MapReduce概述MapReduce是一个用于大规模数据处理的分布式计算模型,它最初是由Google工程师设计并实现的ÿ ... [详细]
  • 对于开源的东东,尤其是刚出来不久,我认为最好的学习方式就是能够看源代码和doc,測试它的样例为了方便查看源代码,关联导入源代 ... [详细]
  • 【转】腾讯分析系统架构解析
    TA(TencentAnalytics,腾讯分析)是一款面向第三方站长的免费网站分析系统,在数据稳定性、及时性方面广受站长好评,其秒级的实时数据更新频率也获得业界的认可。本文将从实 ... [详细]
  • 伸缩性|发生_分布式文件系统设计,该从哪些方面考虑?
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了分布式文件系统设计,该从哪些方面考虑?相关的知识,希望对你有一定的参考价值。点击上方关注“ ... [详细]
  • MapReduce工作流程最详细解释
    MapReduce是我们再进行离线大数据处理的时候经常要使用的计算模型,MapReduce的计算过程被封装的很好,我们只用使用Map和Reduce函数,所以对其整体的计算过程不是太 ... [详细]
  • 于2012年3月份开始接触OpenStack项目,刚开始之处主要是与同事合作共同部署公司内部的云平台,使得公司内部服务器能更好的得到资源利用。在部署的过程中遇到各种从未遇到过的问题 ... [详细]
author-avatar
李太有才_905
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有