使用 orientdb 图 api 与 sql 查询的性能

Perfomance using orientdb graph api vs sql query

实际上我正在使用此 api 进行标准操作(读取、删除、查找、保存) http://orientdb.com/docs/last/Graph-Database-Tinkerpop.html

我注意到这个移除方法的性能真的很差

object Odb {
  val factory = new OrientGraphFactory("remote:localhost:2424/recommendation-system","root","root").setupPool(1,10)

  def clearDb = {
    val graph = factory.getNoTx
    val vertices = graph.getVertices().asScala.map(v => v.remove())
  }
}

object TagsOdb extends TagsDao {
  override def count: Future[Long] = Future {
    val graph = Odb.factory.getNoTx
    val count = graph.countVertices("Tags")
    count
  }

  override def update(newTag: Tag, oldTag: Tag): Future[Boolean] = Future { synchronized {
    val graph = Odb.factory.getTx
    val tagVertices = graph.getVertices("Tags.tag",oldTag.flatten).asScala
    if(tagVertices.isEmpty) throw new Exception("Tag not found: "+oldTag.id)
    tagVertices.head.setProperty("tag",newTag.flatten)
    graph.commit()
    true
  }}


  override def all: Future[List[Tag]] = Future {
    val graph = Odb.factory.getNoTx
    val tagVertices = graph.getVerticesOfClass("Tags").asScala
    val tagList = tagVertices.map(v => Tag(v.getProperty("tag"),None)).toList
    tagList
  }

  override def remove(e: Tag): Future[Boolean] = Future { synchronized {
    val graph = Odb.factory.getTx
    val tagVertices = graph.getVertices("Tags.tag",e.flatten).asScala
    if(tagVertices.isEmpty) throw new Exception("Tag not found: "+e.flatten)
    tagVertices.head.remove()
    graph.commit()
    true
  }}

  override def save(e: Tag, upsert: Boolean = false): Future[Boolean] = Future { synchronized {
    val graph = Odb.factory.getTx
    val v = graph.getVertices("Tags.tag",e.flatten).asScala
    if(v.nonEmpty) {
      if (upsert)
        v.head.setProperty("tag", e.flatten)
      else
        throw new Exception("Element already in database")
    } else {
      val tagVertex = graph.addVertex("Tags", null)
      tagVertex.setProperty("tag", e.flatten)
    }
    graph.commit()
    true
  }}

  override def find(query: String): Future[List[Tag]] = Future {
    val graph = Odb.factory.getNoTx
    val res: OrientDynaElementIterable = graph.command(new OCommandSQL(query)).execute()
    val ridTags: Iterable[Vertex] = res.asScala.asInstanceOf[Iterable[Vertex]]
    def getTag(rid: AnyRef): Tag = {
      val tagVertex = graph.getVertex(rid)
      Tag(tagVertex.getProperty("tag"),None)
    }
    ridTags.map(r => getTag(r)).toList
  }
}

有什么方法可以提高性能吗? 我应该使用 SQL 查询?

由于您是通过远程接口连接的,因此对于每次删除您都有一个 RPC。尝试在服务器上执行 DELETE VERTEX。