如何提高 Zend Framework 应用程序的页面加载速度

发布于 2024-11-03 12:06:51 字数 763 浏览 2 评论 0原文

我使用 ZF 开发了应用程序。该应用程序有点大,但功能很多。

我使用 Zend_Application(已经在构造函数中使用自动加载器)、Zend_Layout、Zend_view、Zend_form 等。我当前的问题是,页面加载速度非常慢,并且在使用 XAMP 的 localhost 中也是如此。

我启用了 xdebug,以调查该问题,在“tmp”文件夹中获取了一个 Cachegrind 文件,并尝试使用 WinCachegrind 软件查看它。在那里我可以看到每个请求或页面加载正在运行许多进程和函数。

另外,我已经为 Firefox 安装了 YSlow 插件,并观察了页面加载的速度(以秒为单位)...我将速度与 ZF 和非 ZF 应用程序进行了比较。从比较来看,非 zf 应用程序的页面加载时间不到 1 秒,而对于 ZF 应用程序,则至少需要 6-7 秒。多么巨大的差异啊。

应用程序中发生的主要事情是:

1)每个请求都会发生数据库连接。

2)我没有显式地将视图添加到布局中,ZF只是根据操作名称自动将其附加到layout.phtml中。

3) 有些窗口的表单带有很少的下拉框,可以从数据库中获取数据。

4)在为每个请求从数据库加载权限之前,已经实现了带有 ACL 的菜单,但现在我已经对其进行了优化,以便它仅在登录期间工作,其余时间将从 Zend_Registry 获取。

我想附加 Cachegrind 文件,以便有人可以看到后台发生的情况,但我在此处看不到用于附加的选项。

请有人帮我找到解决方案。非常感谢任何形式的帮助。多谢

I have developed application using ZF.The app is little big with a lots of features.

I use Zend_Application(already using autoloader in constructor),Zend_Layout,Zend_view,Zend_form,etc. My current issue is, the page loading is very slow and that too in localhost with XAMP.

I have enabled xdebug, to investigate the issue, got a cachegrind file in "tmp" folder and tried to view it with WinCachegrind software. There i can a see a lot of processes and functions being run for each and every request or page load.

Also, i have installed YSlow add-on for firefox and observed the speed of page loads in seconds...I have compare the speed with ZF and non ZF applications. And from the comparison, the pages for non zf app takes less than 1 sec to load and for the ZF app, it takes atleast 6-7 seconds. What a huge difference.

Main Things happen in the app are :

1) Database connection happens for each request.

2) Im not adding the view to layout explicitly,ZF just appends it automatically, to layout.phtml, based on the action name.

3) Some windows have forms with few drop down boxes which fetches data from the database.

4) Have menus with ACL implimented, before it was loading the privilges from DB for each and every request, but now i have optimized it, so that it will work only duiring the login and rest of the time it will take from the Zend_Registry.

I would like to attach the cachegrind file so that some one can see whats happening in the background, but i cant see an option here for attaching.

Someone please help me to find a solution for this. Any kind of help is really appreciated. Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-11-10 12:06:51

让我们尝试给出一些提示。

第一次数据库连接应该只发生一次(除非您在一个或多个数据库上使用多个权限访问)。因此,请检查您是否对 Zend_Db_Tables 对象使用 Singleton 模式

,然后不要使用 Zend_Cache。您确实应该开始使用 Zend_Cache 并构建几个缓存对象。例如,具有长期存储功能的文件缓存和存储对象的内存缓存或 Apc 缓存。然后在几层中使用这些缓存:

  • 将 FileCache 提供给 Zend_Db_Table (defaultMetaDataCache),这样您将避免大量元数据查询,即要求您使用的表的每一列的描述的查询。
  • 存储一个或多个 Acl 对象(取决于您如何使用 Acl,如果您有一个包含所有规则的大 Acl 或多个包含子集的 Acl)。并在构建时将它们存储在中期缓存中。
  • 考虑其他用法,检测重循环、半静态内容(比如您选择列表,有多少次应该将它们视为静态?)

最后,全面了解您的应用程序引擎如何工作,以及您的数据将如何增长和增长您将需要该步骤以最佳方式使用应用程序级别缓存(例如,是否应该为用户组缓存某些元素?是否应该为组、每个用户、每个人构建 Acl 对象?布局中应呈现相同的块大家?)。

Let's try to give some hints.

First database connection should happen only once (except if you use several privileges access on the database or several databases). So check that you use Singleton patterns with you Zend_Db_Tables object

Then you do not use Zend_Cache. You should really start to use Zend_Cache and build several cache objects. Let's say for example a File cach, with long term storage, and a memcache or Apc Cache, storing objects. Then use these cache in several layers:

  • gives the FileCache to Zend_Db_Table (defaultMetaDataCache), this way you will avoid a loot of metadata queries, queries that ask for description of each columns of the tables you use.
  • Store one or more Acl object (depends on how you use Acl, if you have one big Acl with all rules or several with subsets). And store them in mid-duration caches when they are built.
  • Think of other usages, detect heavy loops, semi-static contents (like you select lists, how many time should they be considered static?)

Finally, get a whole mental image of how your application engine works, and how your data will grow and be used.You will need that step to use application levels caches in the very best way (for example should some elements be cached for groups of users?, should Acl objects be build for groups, for each user, for everybody, is ther some blocks in the layout that should be rendered the same for everybody?).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文