Neo4jPhp太慢 [英] Neo4jPhp too slow

查看:125
本文介绍了Neo4jPhp太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我已经从PHP编写了Neo4j的第一个基本程序.这样做基本上是为了检查是否可以通过使用Neo4jPhp在PHP的新项目中使用Neo4j. https://github.com/jadell/neo4jphp

Today i have written first basic program for Neo4j from PHP. This was basically done to check out if we could use Neo4j in our new project from PHP by using Neo4jPhp. https://github.com/jadell/neo4jphp

这是我的代码

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php

include 'neo4jphp.phar';
echo "Hello World!";

// Connecting to the default port 7474 on localhost
$client = new Everyman\Neo4j\Client();
$queryString = 
    "MATCH (n)".
    "RETURN n";
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result = $query->getResultSet();


foreach ($result as $row) {
    echo $row['n']->getProperty('name') . "\n";
}

?>

</body>
</html>

现在,我在这里检索所有具有其属性的节点.很简单

Now here i am just retrieving all the nodes with their property. Pretty simple.

如果我从Neo4j的图形控制台运行此程序,则需要86毫秒.我只有200个节点,并且属性几乎相同.

if i run this from graphical console of Neo4j, it takes 86 ms. I have only 200 nodes and almost same property.

match (n)
return n


Returned 50 rows in 86 ms

如果我从上述PHP文件运行此文件,则总共需要2-4秒才能将数据转储到浏览器中. Neo4j在同一台计算机上运行.

If i run this from above PHP file, it takes 2-4 seconds in total to dump data in browser. Neo4j is running in same machine.

请注意,我没有对PHP和Neo4j的配置进行任何更改.一切都是默认的.请告诉我这是否是Neo4j与PHP的预期行为,或者我的代码或配置确实有问题.

Please note that i have not done any changes in the configuration of both PHP and Neo4j. Everything is default. Please tell me if this is the expected behaviour of Neo4j with PHP or something is really wrong with my code or configuration.

非常感谢

推荐答案

我也在Neo4j Google网上论坛中也看到了您的问题,我问您是否可以用PHP来衡量执行时间,而不是使用

I have seen your question in the Neo4j Google Group as well and I asked if you could measure in PHP the execution time if instead of using the

echo $ row ['n']-> getProperty('name'). "\ n";.

echo $row['n']->getProperty('name') . "\n";.

您使用

print_r($ result);

print_r($result);

让我在下面解释原因. 当我开始使用Neo4j和PHP时,我对速度方面的PHP有效性产生了一些担忧.我像这样重新创建了您的问题.首先,我创建了200个随机节点.每个节点都有一个Label,10个属性,每个属性的值都是10个字符.这是我使用的脚本.

Let me explain below why. When I started to play around with Neo4j and PHP I had some concerns over the effectiveness of PHP in terms of speed. I recreated your issue like so. First I created 200 random nodes. Each node has a Label, 10 properties and each properties has a value of 10 characters. This is te script I used.

for ($x=1; $x<=200; $x++)
  {
  $queryString = "CREATE (n:User { name : '".substr(md5(rand()), 0, 10)."' , city : '".substr(md5(rand()), 0, 10)."' , date : '".substr(md5(rand()), 0, 10)."', age : '".substr(md5(rand()), 0, 10)."', country : '".substr(md5(rand()), 0, 10)."', language : '".substr(md5(rand()), 0, 10)."', origin : '".substr(md5(rand()), 0, 10)."', preference : '".substr(md5(rand()), 0, 10)."', color : '".substr(md5(rand()), 0, 10)."', graduate : '".substr(md5(rand()), 0, 10)."'})";
            $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
            $result = $query->getResultSet();
  } 

使用foreach循环,我得到的结果与您一样

Using the foreach loop I got the result like you did

foreach ($result as $row) {
    echo $row['n']->getProperty('name') . "\n";
}

我测量了使用此代码执行的时间

and I measured the time executed using this code

$time_start = microtime(true);

$queryString = "MATCH (n) RETURN n";
            $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
            $result = $query->getResultSet();

foreach ($result as $row) {
    echo $row['n']->getProperty('name') . "\n";
}

$time_end = microtime(true);


$execution_time = ($time_end - $time_start)*1000;

//execution time of the script
echo '<b>Total Execution Time:</b> '.$execution_time.' ms';

有200个节点,我在85毫秒左右都使用了webadmin和php.数据量不足以获取准确的结果,因此我将节点数增加到500.webadmin和php脚本的执行时间都增加到115ms.将节点增加到2000,我的执行时间为200ms,但是webadmin和php之间没有显着差异.最终,我的节点数达到了10000.现在,我们有了一些结果. Webadmin在1020毫秒内向我返回了10000个节点. php太慢了.

With 200 nodes I got both on webadmin and the php around 85ms. The amount of data is not enough to get accurate results so I increased my nodes to 500. Time execution went up to 115ms both the webadmin and the php script. Increasing my nodes to 2000 I had execution time of 200ms but no significant differences between webadmin and php. Finally I got my nodes up to 10000. Ok now we have some results. Webadmin returns to me 10000 nodes in 1020ms. Php is way too slow though.

总执行时间:1635.6329917908 ms

Total Execution Time: 1635.6329917908 ms

我认为这不是我期望的.我没有使用$ row ['x']方法,而是使用print_r结果和时间增加了

I think this is not what I expect. Instead of using the $row['x'] method I print_r the results and the time increased to

总执行时间:2452.4049758911 ms

Total Execution Time: 2452.4049758911 ms

因此,我认为不要在屏幕上打印所有属性,而只是返回节点和count(n)并查看如果打印每个将为"1"的计数所得到的结果.

So I think lets not print all the properties on the screen but just return the nodes and the count(n) and see what we have if we print the count of each one which will be a "1".

$queryString = "MATCH (n) RETURN n AS n, count(n) AS x";
            $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
            $result = $query->getResultSet();
foreach ($result as $row) {
    echo $row['x'];
}

以上代码的结果将是这样.

The result of the above code will be something like this.

1111111111111111111111 ...... 总执行时间:1084.1178894043 ms

1111111111111111111111...... Total Execution Time: 1084.1178894043 ms

您可以看到php和webadmin同时返回10000个结果(对于10000个节点,我认为60毫秒不是主要区别),并以此得出我的重要答案:在php和Neo4j中,我们不会浪费时间来检索大量数据,而是会浪费很多时间来从PHP在浏览器中呈现这些数据.

As you can see php and webadmin return 10000 results in the same time (for 10000 nodes I do not think that 60 ms are a major difference) and to conclude my big answer with this:in php and Neo4j we do not loose time to retrieve a large amount of data but we loose a lot of time to render this data on our browser from PHP.

这篇关于Neo4jPhp太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆