如果我需要做更多事情来提高网络应用程序的性能,需要一些想法和建议

发布于 2024-10-09 23:29:58 字数 971 浏览 0 评论 0原文

我正在开发一个使用大量ajax来显示数据的网络应用程序,我想知道我是否可以获得任何关于我可以做些什么来加速应用程序并减少带宽等的建议。

我正在使用php 、mysql、freeBSD、Apache、Tomcat 适合我的环境。我拥有服务器并且可以完全访问所有配置文件等。

我在 apache http.conf 文件中打开了 gzip deflate 压缩。我已经混淆并缩小了所有 .js 和 .css 文件。

我的网络应用程序以这种一般方式工作。登录后,用户登陆index.php页面。索引页面上的所有链接都是 ajax 调用来读取 .php 类函数,该函数将检索字符串中的 html 并将其显示在主 index.php 页面上某处的 div 内。

大多数返回 html 的函数都返回如下字符串:

<table>
    <tr>
       <td>Data here</td>
    </tr>
</table>

我不返回完整的“”内容,因为它已经存在于主 index.php 页面中。

然而,返回的html字符串被格式化为制表符、空格、注释等,以便于阅读代码。我应该花时间缩小这些页面并删除选项卡、评论、空格吗?或者缩小 .php 页面是否可以忽略不计,因为它在服务器上?

我想我想弄清楚我构建 web 应用程序的方式是否会导致带宽问题,如果我可以减少 .php 类文件的大小,我是否可以通过减少它们来提高一些性能。大多数 .php 类大小为 40-50KB,最大为 99KB。

为了速度,我考虑过使用内存缓存,但真的不知道事后添加它是否值得,而且我不太知道如何实现它。我不知道服务器上是否打开了任何缓存...我想我已将其留给浏览器...我不太熟悉缓存领域。

现在该网站看起来并不慢,但我是唯一的用户......我只是想知道它是否值得付出额外的努力。

任何建议或文章将不胜感激。

提前致谢。

I'm working on a webapp that uses a lot of ajax to display data and I'm wondering if I could get any advice on what else I could do to speed up the app, and reduce bandwidth, etc.

I'm using php, mysql, freeBSD, Apache, Tomcat for my environment. I own the server and have full access to all config files, etc.

I have gzip deflate compression turned on in the apache http.conf file. I have obfuscated and minified all the .js and .css files.

My webapp works in this general manner. After login the user lands on the index.php page. All links on the index page are ajax calls to read a .php class function that will retrieve the html in a string and display it inside a div somewhere on the main index.php page.

Most of the functions returning the html are returning strings like:

<table>
    <tr>
       <td>Data here</td>
    </tr>
</table>

I don't return the full "<html><head>" stuff, because it already exists in the main index.php page.

However, the html strings returned are formatted with tabs, spaces, comments, etc. for easy reading of the code. Should I take the time to minify these pages and remove the tabs, comments, spaces? Or is it negligible to minify the .php pages because its on the server?

I guess I'm trying to figure out if the way I've structured the webapp is going to cause bandwidth issues and if I can reduce the .php class file size could I improve some performance by reducing them. Most of the .php classes are 40-50KB with the largest being 99KB.

For speed, I have thought about using memcache, but don't really know if adding it after the fact is worth it and I don't quite know how to implement it. I don't know if there is any caching turned on on the server...I guess I have left that up to the browser...I'm not very well versed in the caching arena.

Right now the site doesn't appear slow, but I'm the only user...I'm just wondering if its worth the extra effort.

Any advice, or articles would be appreciated.

Thanks in advance.

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

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

发布评论

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

评论(3

べ映画 2024-10-16 23:29:58

我的建议是不要通过 AJAX 调用发送 HTML。相反,通过 JSON 仅发送底层数据(“此处的数据”部分),然后通过客户端函数处理该数据,该函数将使用正确的 HTML 对其进行修饰,然后将其注入 DOM。这将大大加快 Ajax 调用的速度。

My recommendation would be to NOT send the HTML over the AJAX calls. Instead, send just the underlying data ("Data here" part) through JSON, then process that data through a client-side function that would decorate it with the right HTML, then injecting it into the DOM. This will drastically speed up the Ajax calls.

沒落の蓅哖 2024-10-16 23:29:58

Memcache 提供了一个允许您缓存数据的 API。您还需要(在我看来更重要的是)关于缓存什么以及何时使缓存无效的策略。这不能通过查看源代码来确定,它来自于您的网站的使用方式。

然而,可以立即使用操作码缓存(例如APC)。

Memcache provides an API that allows you to cache data. What you additionally need (and in my opinion more important is) is a strategy about what to cache and when to invalidate the cache. This cannot be determined by looking at the source code, it comes from how your site is used.

However, an opcode cache (e.g. APC) could be used right away.

初见 2024-10-16 23:29:58

代码美化器是给人类用的,不是给机器用的。
作为优化的一部分,您应该起飞。

或者简单地在您的应用程序中添加一个标志检查,某些条件匹配(如调试模式),它会返回格式良好的 JavaScript。否则,空白对机器来说没有任何意义。


APC

您应该始终使用 APC 来编译和使用 APC。将 php 脚本缓存到操作码中

为什么?

  1. 如果每个脚本都已准备好操作码,则部署后很难进行更改
  2. ,您的服务器不需要将纯文本脚本即时编译为二进制操作码
  3. 编译一次并使用多次

>有什么好处?

  1. 编译纯文本脚本的执行周期更短
  2. 内存消耗更少(两者都相关)
  3. 一个简单的数学计算,如果在当前环境中请求在 2 秒内得到服务,现在使用 APC 在 0.5 秒内得到服务,您将获得 4 倍更好的性能,APC 在 2 秒内可以处理 4 个请求。这意味着以前您可以容纳 50 个并发用户,现在您可以允许 200 个并发用户

Memcache - 不行吗?

取决于,如果您处于单主机环境中,可能不会获得任何更好的效果。 memcache最大的优点是信息共享和存储。分布(这意味着多服务器环境,缓存一次,使用多次)。

等等?

  1. 带有过期标头的静态文件(prime 缓存概念,没有请求是最快的,并且节省带宽)
  2. 将昂贵的请求缓存到内存缓存/磁盘缓存甚至数据库中(昂贵的请求,例如报告/统计生成)
  3. 始终检查您的代码以获得最佳优化(但不要过度)
  4. 始终进行基准测试并比较结果(过去和当前)
  5. 微调您的 apache/tomcat 配置
  6. 考虑使用最小的库/扩展重新编译 PHP 并仅在运行时加载必要的库(例如使用 mysqli 的应用程序,不使用 PDO,不保留它的理由)

Code beautifier is for human not for machine.
As part of the optimization you should take off.

Or simply add a flag checking in your application, certain condition match (like debug mode), it return nicely formatted javascript. Otherwise, whitespace does not mean anything to machine.


APC

You should always use APC to compile & cache php script into op-code.

Why?

  1. changes are hardly make after deployment
  2. if every script is op-code ready, your server does not required to compile plain-text script into binary op-code on the fly
  3. compile once and use many

What are the benefits?

  1. lesser execution cycle to compile plain-text script
  2. lesser memory consume (both related)
  3. a simple math, if a request served in 2 seconds in your current environment, now with APC is served in 0.5 seconds, you gain 4 times better performance, 2 seconds with APC can served 4 requests. That's mean previously you can fit 50 concurrent users, now you can allow 200 concurrent users

Memcache - NO GO?

depends, if you are in single host environment, probably not gain any better. The biggest advantages of memcache is for information sharing & distribution (which mean multiple server environment, cache once and use many).

etc?

  1. static files with expiration header (prime cache concept, no request is fastest, and save bandwidth)
  2. cache your expensive request into memcache/disk-cache or even database (expensive request such as report/statistics generation)
  3. always review your code for best optimization (but do not over-do)
  4. always do benchmark and compare the results (was and current)
  5. fine-tune your apache/tomcat configuration
  6. consider to re-compile PHP with minimum library/extension and load the necessary libraries during run-time only (such as application using mysqli, not using PDO, no reason to keep it)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文