开发者

Need some thoughts and advice if I need to do anything more to improve performance of my webapp

开发者 https://www.devze.com 2023-02-01 11:07 出处:网络
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 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 ma开发者_如何转开发in 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.


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.


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.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消