About neo4j multi-threading

971 views
Skip to first unread message

metamoi

unread,
Mar 21, 2012, 2:25:35 AM3/21/12
to Neo4j
I set up the HA configuration of Neo4j with enterprise edition.
After I tested the BMT of the Neo4j with php client API, I found that
it seems that neo4j is single-threaded.
I got about 30~40 requests per second regardless of the number of
users.
If the neo4j is multi-threaded, I think the performance is better.

According to the document of neo4j, single-thread is desirable
because of the uniquness of vertexes(nodes).

I wonder there is any way to run the neo4j with multi-threading.
As the users increase, how can I increase the performance of neo4j?

Peter Neubauer

unread,
Mar 21, 2012, 6:10:43 AM3/21/12
to ne...@googlegroups.com
Hi there,
Neo4j is multithreaded. What you are seeing might be a result of how
your webserver is configured or something else. Normally, if you run
traversals in different threads, you should be able to use the
available cores of your server to increase performance.

Hard to say what is going on without more details ...

/peter

metamoi

unread,
Mar 22, 2012, 4:07:47 AM3/22/12
to Neo4j
Thank you for your reply.

Then, how can I run traversals in different threads?
I used the neo4j RESTful API with php client, which is written on
this neo4j web page: http://docs.neo4j.org/chunked/milestone/tutorials-rest.html

My php code is as follows:

function search($user) {
$client = new Everyman\Neo4j\Client('dnode6', 7474);
$usnIndex = new Everyman\Neo4j\Index\NodeIndex($client,
'usn');

$traversal = new Everyman\Neo4j\Traversal($client);
$traversal->addRelationship('FRIEND', Everyman\Neo4j
\Relationship::DirectionOut)
->setPruneEvaluator(Everyman\Neo4j
\Traversal::PruneNone)
->setReturnFilter(Everyman\Neo4j\Traversal::ReturnAll)
->setMaxDepth(1);

$startNode = $usnIndex->findOne('usn', $user);
$nodes = $traversal->getResults($startNode, Everyman\Neo4j
\Traversal::ReturnTypeNode);

$result = array();
foreach ($nodes as $node) {
$friends = $traversal->getResults($node, Everyman\Neo4j
\Traversal::ReturnTypeNode);
foreach ($friends as $friend) {
$usn = $friend->getProperty('usn');
try {
$count = $result[$usn];
} catch(Exception $e) {
$count = 0;
}

$result[$usn] = $count+1;
}
}

arsort($result);
$count = 1;
foreach (array_keys($result) as $key) {
if ($key != $user)
print $count++ . " : " . $key . " --> " .
$result[$key]. "\n";
}
}

With the above 'search function', the response time is getting slower
as the concurrent users increase.
I think if neo4j is multithreaded, the response time is not to slow.

Michael Hunger

unread,
Mar 22, 2012, 6:29:59 AM3/22/12
to ne...@googlegroups.com, Josh Adell
Would it be possible for you to generate a thread dump of the neo4j server while you are running those many concurrent users.

kill -3 <pid> should add it to the server logs.

You are doing
#1 one index lookup
#2 traversal to friends with max-depth 1 for each of the found nodes (which should be just one user-node)
#3 for each of the friends getting one property and accumulating them

Correct? And this concurrently for many users.

I'm not sure how the neo4j-php client transforms those into rest-operations, probably at least 2-3 server calls

would be interesting to compare it with the appropriate cypher statement, which does these things in one go

start user=node:usn(usn={username} match user-[:FRIEND]->friend return friend.usn

Michael

Reply all
Reply to author
Forward
0 new messages