【问题标题】:OrientDB: how to speed up import from Blueprint Java API?OrientDB:如何加快从 Blueprint Java API 导入?
【发布时间】:2015-11-11 16:51:41
【问题描述】:

我在使用 Blueprint Java API 在 OrientDB 中的数据摄取非常缓慢。 具体来说,我使用plocal 模式和OrientGraphNoTx 类从几个CSV 文件中加载~1M 节点和3M 边(不幸的是我不能使用ETL,因为它不允许我读取包含边的文件在现有节点之间)。 代码用 Scala 编写,运行大约一个半小时。

数据库的模式包含 5 个顶点类、7 个边类和 6 个索引。我用来创建边的属性使用unique_hash_indexes 进行索引。 在现有节点之间创建边是最耗时的操作(可能是因为边很多),下面是我使用的代码。 有人知道如何优化它吗?

/**
 * Adds edges to the graph.
 * Assumes edgesPath points to a CSV file with format (from, to)
 */
def addEdges(edgesPath: String,
             fromTable: String, fromAttribute: String,
             toTable: String, toAttribute: String,
             edgeType: String, graph: OrientGraphNoTx) {

  logger.info(s"Adding edges from '$edgesPath'...")
  val in = Files.newBufferedReader(Paths.get(edgesPath), Charset.forName("utf-8"))
  val records = CSVFormat.DEFAULT
    .withHeader("from", "to")
    .withSkipHeaderRecord(hasHeader)
    .parse(in)
  var errors = 0
  for (r <- records) {
    val (src, target) = (r.get("from"), r.get("to"))
    if (src != "" && target != "") {
      try {
        graph.command(new OCommandSQL(s"CREATE EDGE $edgeType FROM (" +
          s"SELECT FROM $fromTable WHERE $fromAttribute = '$src') " +
          s"TO (SELECT FROM $toTable WHERE $toAttribute ='$target')")).execute()
      } catch {
        case e: OCommandExecutionException => errors += 1
      }
    } //if
  } //for
  if(errors > 0)
    logger.warn(s"Couldn't create $errors edges due to missing sources/targets or internal errors")
  logger.info("done.")
} //addEdges

【问题讨论】:

    标签: orientdb tinkerpop-blueprint


    【解决方案1】:

    如果您在 plocal 中工作并且需要一批导入 尝试为您的导入器禁用 WAL

    OGlobalConfiguration.USE_WAL.setValue(false);
    

    【讨论】:

    • 感谢您的建议;它现在正在运行。我会告诉你的。
    • 不幸的是,执行时间几乎没有改善:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多