问题描述
你好,
我不是LAMP专家,我的一个朋友正在运行一个有点超载的网站。在升级之前,他想确保没有
简单的方法来提高效率。
一些事情:
- MySQL:尽可能地,他将查询结果保存在RAM中,但显然,每个都是特定于会话的,这意味着结果不可能是$ /
与其他用户共享。
是否有可以在该领域完成的事情,即。在RAM中保留最大数量的MySQL数据,以避免用户(登录和
来宾)一次又一次地攻击单个MySQL服务器?
- 他的主人说Apache服务器负载很重。
这一点,我没有更多细节,但一般来说,什么
是优化PHP应用程序的众所周知的方法?
谢谢。
你确定在ram中保存数据是一个很好的解决方案吗? MySQL缓存
dosen`t help?
为了方便测试,尝试安装PHP加速器(我已经测试了
eaccelerator )。它可以做得很好。
还有一件事,试着确保服务器过载
处理的东西而不是因为一个糟糕的缓存机制(google for
浏览器缓存)。根据经验,不要使用php生成的
图片,或其他动态生成的内容,如果它不是真的需要
。
没有简单的方法来优化PHP,就像使用任何其他语言一样,你需要知道你的脚本到底出了什么问题。您可以使用
xdebug(作为分析器)来查看哪些函数占用了大量资源。
您可以监视服务器,看看他为什么放慢速度/>
那个(需要更多的ram,更多cpu的...更多的硬盘?)。
通过RAM,我的意思是保留内存而不是从HD读取它们,即使它没有必要数据没有改变。
我会检查一下。
这就是他遇到的问题:如果我必须调查哪些事情可以在Linux + Apache + PHP +中优化
MySQL,我应该使用什么工具?
谢谢
你确定在ram中保存数据是一个很好的解决方案吗? MySQL缓存
dosen`t帮助?
无论如何它都是通过磁盘缓存保存的。
可能:-)
如果您对同一组表时间和
再次运行查询,那么这些表将由OS缓存。
如果计算机的RAM空间不足,预计会出现性能突然大幅下降的情况。
这是机器所有者修理的东西。
有时搞砸dB应用程序的另一件事是搜索
无索引字段。添加索引通常可以提供很多帮助,因为可以优化嵌套选择语句的完成方式。
关键是最早可以减少数量数据,如果
可能首先搜索索引字段..
为了方便测试,尝试安装PHP加速器(我已经测试了
eaccelerator )。它可以做得很好。
还有一件事,试着确保服务器过载
处理的东西而不是因为一个糟糕的缓存机制(google for
浏览器缓存)。根据经验,不要使用php生成的
图片,或其他动态生成的内容,如果它不是真的需要
。
如果不能访问机器,这是一个很难知道什么是慢的。它因为低RAM和太多的磁盘访问而受到I / O限制,进程受限
- RAM可用的进程太多 - 或者只是CPU绑定
做太多的计算。我的经验表明,大多数情况下你不需要在*服务器*中需要巨大的CPU功率,但需要更快的磁盘或更好的磁盘,以及几个磁盘和大量的磁盘。 RAM是关键。正如一个快速的网络......在某些更恶劣的SQL查询中,只有一个问题,CPU功能会出现问题,而这些通常是通过重写查询或索引来修复的。
任何动态的图形计算当然会搞砸CPU,但是大多数人都不会这样做... b更有可能是图像是只是
检索,而不是生成...
这是一个有趣的观点...... PHP可以轻松搞定像CPU使用,b $ b利用率,内存资源分配等等?那么一个人可以建立一个
a的网页来点对服务器吗?
我不介意其中的一个......
Hello,
I''m no LAMP expert, and a friend of mine is running a site which is a
bit overloaded. Before upgrading, he''d like to make sure there''s no
easy way to improve efficiency.
A couple of things:
- MySQL : as much as possible, he keeps query results in RAM, but
apparently, each is session-specific, which means that results can''t
be shared with other users.
Is there something that can be done in that area, ie. keep the maximum
amount of MySQL data in RAM, to avoid users (both logged-on and
guests) hitting the single MySQL server again and again?
- His hoster says that Apache server is under significant load. At
this point, I don''t have more details, but generally speaking, what
are the well-know ways to optimize PHP apps?
Thank you.
Are you sure keeping data in ram is a good solution? MySQL cache
dosen`t help?
For an easy test try to install a PHP accelerator (i`ve testesd
eaccelerator http://eaccelerator.net/ ). It can do a pretty good job.
And another thing , try to make sure that the server is overloaded
procesing stuff and not because of a bad caching mechanism (google for
browser-caching). As a rule of thumb , do not use php-generated
images, or other dinamically generated content if it`s not really
needed.
There is no easy way to optimize PHP,as with any other language you
have to know exactly what goes wrong with your scripts. You can use
xdebug (as a profiler) to see what functions eat a lot of resources.
You can monitor the server and see why he is slowing down like
that(need more ram, more cpu`s...more hdd?).
By RAM, I meant keeping stuff in memory vs. reading them from the HD,
even though it''s not necessary since data didn''t change.
I''ll check it out.
That''s the problem he has: If I had to investigate where things can be
optimized in Linux + Apache + PHP + MySQL, what tool should I use?
Thanks
Are you sure keeping data in ram is a good solution? MySQL cache
dosen`t help?
Its all held in ram by disk caching anyway.
Probably :-)
If you are running queries against the same sets of tables time and
again, those tables will be cached by the OS.
If the computer runs out of free RAM tho, expect a sudden and huge
downturn in performance.
That something for the machine owner to fix tho.
The other thing that sometimes screw up dB apps is searches on
un-indexed fields. Adding indexes can often help a lot, as can
optimising the way nested select statements are done.
The key is that the earliest you can reduce the amount of data, if
possible searching on indexed fields first..
For an easy test try to install a PHP accelerator (i`ve testesd
eaccelerator http://eaccelerator.net/ ). It can do a pretty good job.
And another thing , try to make sure that the server is overloaded
procesing stuff and not because of a bad caching mechanism (google for
browser-caching). As a rule of thumb , do not use php-generated
images, or other dinamically generated content if it`s not really
needed.
Its a hard call to know what is slow without access to the machine. It
may be I/O bound due to low RAM and too many disk access, process bound
- too many processes for the RAM avaialable - or simply CPU bound having
to do too much computation. My experience suggests that mostly you don''t
need huge CPU power in a *server*, but a fast disk or better, several
disks, and huge amounts of RAM are the key. As is a fast network..only
in some of the nastier SQL queries does CPU power get an issue, and
those are generally fixed by rewriting te query or indexing.
Any on the fly graphics computation will of course screw the CPU, but
most people don''t do that..its more likely the images are just being
retrieved, not generated...
That''s an interesting point..can PHP easily get at things like CPU
utilisation, memory resoure allocation and the like? so one could build
a web page to peer into the server?
I wouldn''t mind one of those here..
这篇关于减少LAMP应用程序的负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!