如何使用 Zend_Lucene 和 Zend_Paginator 优化大量数据库记录的索引
因此,我有一个使用 Cron 在主机上部署和运行的 cron 脚本,并对数据库表中的所有记录进行索引 - 该索引稍后也用于站点的前端和支持的操作。
运行后索引大约有3-4MB。
问题是它需要大量资源(CPU:30+ 和大量内存)并降低机器速度。我的问题是关于如何优化下面描述的操作:
首先有一个使用 Zend Framework API 构建的选择查询,然后将该查询传递到一个分页器工厂,该工厂返回一个分页器,我用它来平衡当前正在处理的项目数。索引并且不会迭代太多项目。 该脚本使用 foreach 循环迭代分页器对象中的当前项目,直到到达末尾,然后在获取下一页的项目后从头开始。
我怀疑这个开销是由 Zend_Lucene 引起的,但不知道如何改进。
So I have this cron script that is deployed and ran using Cron on a host and indexes all the records in a database table - the index is later used both for the front end of the site and the backed operations as well.
After the operation, the index is about 3-4 MB.
The problem is it takes a lot of resources (CPU: 30+ and a good chunk of memory) and slows the machine down. My question is about how to optimize the operation described below:
First there is a select query built using the Zend Framework API, this query is then passed to a Paginator factory that returns a paginator which I am using to balance the current number of items being indexed and not iterate over too much items.
The script is iterating over the current items in the paginator object using a foreach loop until reaching the end and then it starts from the beginning after getting items for the next page.
I am suspecting this overhead is caused by the Zend_Lucene but no idea how this could be improved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我对 我可以预测我的 Zend Framework 索引有多大吗?
我测试了 Zend_Search_Lucene 与 Apache Lucene(Java 版本)。在我的测试中,Java 产品索引 150 万个文档的速度比 PHP 产品快约 300 倍。
使用 Apache Solr(Apache Lucene 的 Tomcat 容器)会让您更加高兴。 Solr 包含一个名为 DataImportHandler 的工具,它直接从 JDBC 数据源获取数据。
使用 PECL Solr 扩展从 PHP 与 Solr 进行通信。如果您无法安装该 PHP 扩展,请使用 Curl,它应该在 PHP 默认安装中可用。
See my answer to Can I predict how large my Zend Framework index will be?
I tested Zend_Search_Lucene versus Apache Lucene (the Java version). In my test, the Java product indexed 1.5 million documents about 300x faster than the PHP product.
You'll be much happier using Apache Solr (the Tomcat container for Apache Lucene). Solr includes a tool called DataImportHandler that sucks data directly from a JDBC data source.
Use the PECL Solr extension to communicate with Solr from PHP. If you can't install that PHP extension, use Curl which should be available in default installations of PHP.