简体   繁体   English

缩放灯

[英]Scaling LAMP

I have a client with a LAMP website serving mostly video.我有一个 LAMP 网站的客户,主要提供视频服务。 He is currently on one server with all components.他目前在一台装有所有组件的服务器上。 He is having some scaling problems.他有一些缩放问题。 What are some of the techniques that can be used to help.有哪些技术可以用来帮助。

I used separating out the DB to another server with a GB Ethernet between it and the webserver.我使用将数据库分离到另一台服务器,在它和网络服务器之间有一个 GB 以太网。 Maybe adding more web servers with some load balancing and additional MySQL servers with replication?也许添加更多带有负载平衡的 Web 服务器和带有复制功能的其他 MySQL 服务器?

Would like some medium, large, super large examples on how to scale if possible.如果可能的话,想要一些关于如何扩展的中型、大型、超大型示例。

The video is actually coming as jpg images.该视频实际上是 jpg 图像。 Similiar to this website:类似于这个网站:

http://www.webcams.travel/webcam/1170170095 http://www.webcams.travel/webcam/1170170095

And to add some details.并添加一些细节。 I figure the max visitors per hour would be 1000, and I think would be lucky to have that.我认为每小时的最大访客数将是 1000,我认为拥有它会很幸运。 Maybe closer to 1000 a day.也许每天接近1000。

The advice about CloudFront and MemCache etc. is all good, assuming those address the root of your performance issues.关于 CloudFront 和 MemCache 等的建议都很好,假设它们解决了性能问题的根源。

On the database side: Profile, profile, profile.在数据库方面:配置文件、配置文件、配置文件。 Moving the DB to a separate server was (probably) a good step, but if you haven't profiled the queries being run on this DB instance, you don't know what you need to improve.将数据库移动到单独的服务器是(可能)一个很好的步骤,但是如果您还没有分析在这个数据库实例上运行的查询,您不知道您需要改进什么。

Start by doing an EXPLAIN on the most common queries, and check whether you're doing unnecessary sequential scans on large or growing tables.首先对最常见的查询执行EXPLAIN ,然后检查您是否对大型表或不断增长的表进行了不必要的顺序扫描。 Index as necessary.根据需要编制索引。

Are any of the queries passing back columns that aren't used?是否有任何查询传回未使用的列?

Are you, as other commenters were worried, serving your graphic/video content from the database?您是否如其他评论者所担心的那样,从数据库中提供您的图形/视频内容? Files should be kept in the filesystem, and served from there.文件应该保存在文件系统中,并从那里提供。

Are all your tables MyISAM?你所有的表都是 MyISAM 吗? Frequently-updated tables may show performance improvement by moving them to InnoDB , where they can benefit from row-level locking (as opposed to MyISAM's table-level locking).频繁更新的表可以通过将它们移动到InnoDB来显示性能改进,在那里它们可以受益于行级锁定(与 MyISAM 的表级锁定相反)。

These are just simple, general recommendations - without more specifics on exactly what is slow, it's tough to offer anything deeper.这些只是简单的一般性建议 - 没有更多关于到底什么是缓慢的细节,很难提供更深入的内容。

First off, I agree that you must know what the bottleneck is before attempting to scale.首先,我同意在尝试扩展之前您必须知道瓶颈是什么。 Here some run of the mill suggestions to get you started:以下是一些帮助您入门的工厂建议:

  1. Get video out of the database.从数据库中获取视频。 I don't see how this would make sense in any situation.我不明白这在任何情况下都有什么意义。

  2. Add one more server to only server the video content and leave the HTML/application to the original one.再添加一台服务器以仅为视频内容提供服务,而将 HTML/应用程序保留为原始服务器。 Not only does this reduce load, but it creates a performance improvement on the client side by overcoming any HTTP connection limits .这不仅减少了负载,而且通过克服任何HTTP 连接限制来提高客户端的性能。

  3. Cache - This may mean Memcahce or just pre-building HTML output instead of dynamically processing it for every request.缓存 - 这可能意味着Memcahce或只是预先构建 HTML 输出,而不是为每个请求动态处理它。

  4. If you are fortunate enough to reach 'super large' you might think about a CDN .如果您有幸达到“超大”,您可能会考虑CDN I'm sure you will encounter many other hurdles before then though.我相信在此之前您会遇到许多其他障碍。

Best of luck.祝你好运。

You need to work out exactly what the problem is - there is no general solution.你需要弄清楚到底是什么问题——没有通用的解决方案。

You need to build a performance test environment with real hardware and something which can simulate lots of clients.您需要使用真实的硬件和可以模拟大量客户端的东西来构建性能测试环境。 This may be quite expensive.这可能相当昂贵。

If the problem is the database (which it may be) then the solution is often to split it into several databases each holding part of the data.如果问题出在数据库(可能是),那么解决方案通常是将其拆分为多个数据库,每个数据库都保存部分数据。

But I wouldn't imagine that any sane person would store video on MySQL - if he is doing that, then a refactoring may be in order.但我不会想象任何理智的人会在 MySQL 上存储视频 - 如果他这样做,那么重构可能是有序的。

Profile to see how much load various parts of his site actually inflict.配置文件以查看其站点的各个部分实际造成的负载。

I presume most of the load is actually serving the videos - use a proxy to redirect this work to a second (,third, fourth...) server.我认为大部分负载实际上是为视频提供服务 - 使用代理将这项工作重定向到第二个(、第三、第四...)服务器。

Barrett's answers are pretty much what I would do -- id the bottlenecks, look at memcached, move the DB to a separate server from web services, etc. Barrett 的回答几乎就是我会做的——找出瓶颈,查看 memcached,将数据库从 Web 服务移到单独的服务器,等等。

I would add that Amazon has a new service called CloudFront that will serve up content from geographically close servers.我想补充一点,亚马逊有一项名为CloudFront的新服务,它将提供来自地理位置接近的服务器的内容。 I haven't given it a try yet, but that may be a way to spread the load for a relatively low cost.我还没有尝试过,但这可能是一种以相对较低的成本分散负载的方法。

Also, look at the presentations from Livejournal and Facebook on how they scale their systems, they may provide some insight depending on how you have your applicaiton(s) structured.此外,请查看 Livejournal 和 Facebook 关于他们如何扩展系统的演示,它们可能会根据您的应用程序结构提供一些见解。

You should profile the application to start with and find out where the bottlenecks are - if it's PHP, using something like xdebug would be a good start.您应该首先分析应用程序并找出瓶颈所在 - 如果是 PHP,使用 xdebug 之类的东西将是一个好的开始。 It may be that you spend a long time serializing data, or talking to a database - so perhaps caching with Memcached may help.可能是您花费了很长时间序列化数据或与数据库交谈 - 因此使用 Memcached 进行缓存可能会有所帮助。

Secondly, if you're using MySQL, turn on MySQL slow query log (log_slow_queries in my.cnf);其次,如果你使用的是MySQL,开启MySQL慢查询日志(my.cnf中的log_slow_queries); this can be used to give you an idea of what the expensive database queries are and once you know that you can target tuning them via EXPLAIN <> as has already been mentioned.这可用于让您了解昂贵的数据库查询是什么,并且一旦您知道可以通过 EXPLAIN <> 来调整它们,正如已经提到的那样。 It may be the case that you just need to add a few indexes to the database, at which point it'll become quick again.可能的情况是您只需要向数据库添加一些索引,此时它会再次变得很快。 There are other relevant my.cnf parameters to eg log queries not using an index.还有其他相关的 my.cnf 参数,例如不使用索引的日志查询。

Thirdly, look into tools like Yahoo's page speed firefox plugin - it'll make some suggestions (eg offload static content, compress stuff you're returning, make sure you have expires headers etc.).第三,查看像 Yahoo 的页面速度 firefox 插件这样的工具 - 它会提出一些建议(例如卸载静态内容,压缩你返回的内容,确保你有过期的标题等)。 Perhaps the server(s) themselves aren't the bottleneck, and pages are taking a long time to render due to a dependency on a third party (external JS, adverts, flash ...).也许服务器本身不是瓶颈,并且由于依赖第三方(外部 JS、广告、flash ...),页面需要很长时间才能呈现。

You'll need to have some idea of how busy your database server is, compared to your web server, to know where you need to add additional hardware (ie do you need multiple web servers with a front end load balancer, or do you need multiple database servers with replication or both?).与 Web 服务器相比,您需要了解数据库服务器的繁忙程度,以了解需要添加额外硬件的位置(即,您是否需要多个带有前端负载平衡器的 Web 服务器,或者您是否需要具有复制功能或两者兼有的多个数据库服务器?)。

I'm sure there are loads more that can be said...我敢肯定还有很多可以说的......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM