cnhx27
(Cnhx27)
December 18, 2019, 6:30pm
1
Hi,
I'm new to Neo4j and I've been playing around with the whole platform. Lately, I've been experimenting with interacting with the DB from a Go program.
To do this, I rewrote this GO code goneo-example using neo4j-go-driver
.
For the merge
function, I did this
func merge(absoluteURL string, depth int, neo4jDriver neo4j.Driver) error {
var (
neo4jSession neo4j.Session
err error
)
if neo4jSession, err = neo4jDriver.Session(neo4j.AccessModeWrite); err != nil {
return err
}
defer neo4jSession.Close()
_, err = neo4jSession.Run("MERGE (p: page {url: $url, depth: $depth}) RETURN p", map[string]interface{}{
"url": absoluteURL,
"depth": depth,
})
//_, err = neo4jSession.Run("CREATE ()", nil)) // Also poor perfomance
return err
}
But I'm getting weaker performance (also with CREATE ()
).
In the documentation it says:
The driver is thread-safe, while the session or the transaction is not thread-safe.
It is considerably cheap to create new sessions and transactions.
I don't understand why I have poor performance.
freeeve
(Freeeve)
December 18, 2019, 8:25pm
2
Do you have an index or node key for :Page(url, depth) ?
for example:
CREATE CONSTRAINT ON ( page:page ) ASSERT (page.url, page.depth) IS NODE KEY;
cnhx27
(Cnhx27)
December 19, 2019, 7:23am
3
None of that. Start with empty Neo4j database. Performance is quite acceptable with golang-neo4j-bolt-driver
Check out the newer version here, blog posts and examples are coming soon:
Yes please follow Eve's advice and add an constraint for :page(url)
if that's unique by URL.
cnhx27
(Cnhx27)
December 19, 2019, 12:33pm
5
I successfully use johnnadratowski /golang-neo4j-bolt-driver . What's your fork?
According to your indications, this constraint must be added before any cypher order merge
or create
.
CREATE CONSTRAINT ON ( page:url) ASSERT (page.url) IS NODE KEY;
Is that right?
IS UNIQUE is enough there, NODE KEY is for composite indexes.
you can add constraints any time, they just might fail if you have duplicates
the improved fork is this one: GitHub - mindstand/golang-neo4j-bolt-driver: Golang Bolt driver for Neo4j
cnhx27
(Cnhx27)
December 19, 2019, 1:59pm
7
OK. Thank for your help.
Can you tell me how this fork is improved?