Very slow connecting

performance
connection

(Michaelklaus77) #1

Hello all,
i think i have a connection problem from my local Apache-Server to my local Neo4j-Server.
The connection always takes about a second. Can this be a configuration problem? I use the default configuration from Neo4j in version 3.4.1 and PHP 7.1. How long does it usually take to create the session?
Here is my code snippet.

require_once '../vendor/autoload.php';
use GraphAware\Bolt\GraphDatabase;
$config = GraphAware\Bolt\Configuration::create()
            ->withCredentials('neo4j', 'test');
$driver = GraphDatabase::driver("bolt://localhost", $config);
$session = $driver->session();
//$session->run('MATCH (n:Person) RETURN n LIMIT 25');
$session->close();

(Michaelklaus77) #2

i've used other Frameworks to connect, the problem is the same. With the client from "Neoxygen" it only need 450ms for the first Query. Thats better, but way to long for productiv use. The second Query is no more measurable, because its to fast. The Problem is, that my application asks each single request to an php-backend, so the backend must etablish a new connect for every request.


(Christophe Willemsen) #3

With the following script, I return 1000 nodes in 24ms, on a local database. I would check that the latency between your app and the db isn't too high, or check also the dns resolution.

<?php

require_once __DIR__ .'/vendor/autoload.php';

$client = \GraphAware\Neo4j\Client\ClientBuilder::create()
    ->addConnection('default', 'bolt://neo4j:pass@localhost:7687')
    ->build();

$t = microtime(true);
$query = 'MATCH (n:Keyword) RETURN n.value LIMIT 10000';
$result = $client->run($query);
foreach ($result->records() as $record) {
	//
}


echo sprintf('Retrieved %d nodes in %f \n', $result->size(), (microtime(true) - $t));
ikwattro@mbp666-019 ~/d/phptest> php test.php
Retrieved 1001 nodes in 0.024429 \n⏎

(Michaelklaus77) #4

If I use "127.0.0.1" instead of "localhost" I will get similar times. Compared to a Mysql connection the performance of Neo4j is still too bad.

#Test with Neo4j

$t = microtime(true);
require_once __DIR__ .'/vendor/autoload.php';

$client = \GraphAware\Neo4j\Client\ClientBuilder::create()
    ->addConnection('default', 'bolt://neo4j:test@127.0.0.1:7687')
    ->build();

$query = 'MATCH (n:Tool) RETURN n LIMIT 10000';
$result = $client->run($query);


echo sprintf('Retrieved %d nodes in %f \n', $result->size(), (microtime(true) - $t));
C:\xampp\php
λ php d:\htdocs\neo4j_test.php
Retrieved 5 nodes in 0.038917 \n

C:\xampp\php
λ php d:\htdocs\neo4j_test.php
Retrieved 5 nodes in 0.041869 \n

#Test with Mysql

<?php
$t = microtime(true);

$link = mysqli_connect("127.0.0.1", "root", "", "testdb");
$sql_statement = "SELECT * FROM tools";
$result= $link->query($sql_statement);

$arr = array();
while ($row = $result->fetch_row()) {
    $arr[] = $row;
}
$link->close();

echo sprintf('Retrieved %d rows in %f \n', count($arr), (microtime(true) - $t));
C:\xampp\php
λ php d:\htdocs\mysql_test.php
Retrieved 5 rows in 0.001356 \n

C:\xampp\php
λ php d:\htdocs\mysql_test.php
Retrieved 5 rows in 0.000970 \n