我正在開發一個可以在圖形數據庫(Titan)中很好地工作的應用程序,除了它有許多邊的頂點問題,即supernodes。Titan中的「超節點」
上面的超節點鏈接指向Titan作者的博客帖子,解釋瞭解決問題的方法。該解決方案似乎通過邊緣過濾來減少頂點的數量。
不幸的是我想groupCount
邊或頂點的屬性。例如,我有100萬用戶,每個用戶都屬於一個國家。我怎樣才能做出快速的groupCount
來計算每個國家的用戶數量?
我已經試過到目前爲止可以在這個精心設計的Groovy腳本顯示:
g = TitanFactory.open('titan.properties') // Cassandra
r = new Random(100)
people = 1e6
def newKey(g, name, type) {
return g
.makeType()
.name(name)
.simple()
.functional()
.indexed()
.dataType(type)
.makePropertyKey()
}
def newLabel(g, name, key) {
return g
.makeType()
.name(name)
.primaryKey(key)
.makeEdgeLabel()
}
country = newKey(g, 'country', String.class)
newLabel(g, 'lives', country)
g.stopTransaction(SUCCESS)
root = g.addVertex()
countries = ['AU', 'US', 'CN', 'NZ', 'UK', 'PL', 'RU', 'NL', 'FR', 'SP', 'IT']
(1..people).each {
country = countries[(r.nextFloat() * countries.size()).toInteger()]
g.startTransaction()
person = g.addVertex([name: 'John the #' + it])
g.addEdge(g.getVertex(root.id), person, 'lives', [country: country])
g.stopTransaction(SUCCESS)
}
t0 = new Date().time
m = [:]
root = g.getVertex(root.id)
root.outE('lives').country.groupCount(m).iterate()
t1 = new Date().time
println "groupCount seconds: " + ((t1 - t0)/1000)
基本上一個根節點(泰坦沒有一個「全」節點查找的緣故),與許多person
通過具有country
屬性的邊。當我在一百萬個頂點上運行groupCount()時,花費一分多鐘。
我意識到泰坦可能在迭代每個邊緣並收集計數,但是有沒有一種方法可以使Titan或任何其他圖形數據庫的運行速度更快?指數本身是否可以計算,因此它不需要遍歷?我的索引是否正確?