Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么使用spark submit将4000个图像加载到redis要比将相同的图像加载到HBase(2.5分钟)花费更长的时间(9分钟)?_Redis_Hbase_Spark Submit - Fatal编程技术网

为什么使用spark submit将4000个图像加载到redis要比将相同的图像加载到HBase(2.5分钟)花费更长的时间(9分钟)?

为什么使用spark submit将4000个图像加载到redis要比将相同的图像加载到HBase(2.5分钟)花费更长的时间(9分钟)?,redis,hbase,spark-submit,Redis,Hbase,Spark Submit,将图像加载到Redis应该比使用Hbase做同样的事情快得多,因为Redis处理RAM,而Hbase使用HDFS存储数据。当我将4000张图片加载到Redis时,我很惊讶,它花了9分钟才完成!虽然我使用HBase完成了相同的过程,但只花了2.5分钟。这有什么解释吗?有什么改进我的代码的建议吗?这是我的密码: // The code for loading the images into Hbase (adopted from NIST) val conf = new SparkConf().se

将图像加载到Redis应该比使用Hbase做同样的事情快得多,因为Redis处理RAM,而Hbase使用HDFS存储数据。当我将4000张图片加载到Redis时,我很惊讶,它花了9分钟才完成!虽然我使用HBase完成了相同的过程,但只花了2.5分钟。这有什么解释吗?有什么改进我的代码的建议吗?这是我的密码:

// The code for loading the images into Hbase (adopted from NIST)
val conf = new SparkConf().setAppName("Fingerprint.LoadData") 
val sc = new SparkContext(conf) 
Image.dropHBaseTable() Image.createHBaseTable() 
val checksum_path = args(0) 
println("Reading paths from: %s".format(checksum_path.toString)) 
val imagepaths = loadImageList(checksum_path) println("Got %s images".format(imagepaths.length))
imagepaths.foreach(println) 
println("Reading files into RDD") 
val images = sc.parallelize(imagepaths).map(paths => Image.fromFiles(paths._1, paths._2)) 
println(s"Saving ${images.count} images to HBase")
Image.toHBase(images) 
println("Done")

} val conf = new SparkConf().setAppName("Fingerprint.LoadData") val sc = new SparkContext(conf) Image.dropHBaseTable() Image.createHBaseTable() val checksum_path = args(0) println("Reading paths from: %s".format(checksum_path.toString)) val imagepaths = loadImageList(checksum_path) println("Got %s images".format(imagepaths.length)) imagepaths.foreach(println) println("Reading files into RDD") val images = sc.parallelize(imagepaths) .map(paths => Image.fromFiles(paths._1, paths._2)) println(s"Saving ${images.count} images to HBase") Image.toHBase(images) println("Done")

} def toHBase(rdd: RDD[T]): Unit = {

     val cfg = HBaseConfiguration.create()
     cfg.set(TableOutputFormat.OUTPUT_TABLE, tableName)
     val job = Job.getInstance(cfg)
     job.setOutputFormatClass(classOf[TableOutputFormat[String]])
     rdd.map(Put).saveAsNewAPIHadoopDataset(job.getConfiguration)

} 
//将图像加载到Redis的代码

  val images = sc.parallelize(imagepaths).map(paths => Image.fromFiles(paths._1, paths._2)).collect
        for(i <- images){
val stringRdd = sc.parallelize(Seq((i.uuid, new String(i.Png, StandardCharsets.UTF_8))))
        sc.toRedisKV(stringRdd)(redisConfig)
        stringRdd.collect}                    
        println("Done")
val images=sc.parallelize(imagepath).map(path=>Image.fromFiles(path.\u 1,path.\u 2)).collect

对于(i Mmmm-这将取决于您尚未指定的环境以及映像的大小和磁盘的类型。带有SD卡和512MB RM的Raspberry Pi Zero可能与带有SSD驱动器和128GB RAM的16核工作站的性能有所不同……此外,Redis是单线程的……您使用什么客户端库连接到redis?你从多少线程和物理机器上传它们?感谢你的回复Imas,我有一个包含三个虚拟机的集群,用于Redis和Hbase。我对两者使用相同的硬件配置。以下是与Redis配置相关的代码:val conf=new SparkConf().setMaster(“纱线集群”).setAppName(“LoadDataIntoRedis”)val sc=new SparkContext(conf)val rediserverdnsaddress=“..**”val redisPortNumber=6379 val redisPassword=“*********”val redisConfig=new redisConfig(new redispendent(rediserverdnsaddress,redisPortNumber,redisPassword))我只是在使用这个库:import com.redislabs.provider.redis.@MarkSetchell你怎么知道redis是单线程的?我有一个主节点,两个从节点。每个节点有6G RAM,两个内核,4G交换。数据集的大小约为900 MB。当我检查每个节点的交换大小时,我发现所有节点的交换大小都减小了,即使两个从机的RAM大小仍然超过2GB。这也让我感到惊讶,为什么即使从机节点有足够的RAM容量,足以容纳加载的数据集,也要使用交换?谢谢。