如何扩展web应用程序

时间:2021-01-21 20:12:57

My basic question is: How to start building a web application that could grow fast?

我的基本问题是:如何开始构建能够快速增长的web应用程序?

A little background: A customer of me is asking for an offer for a web application. I can not go into details but it's an e-commerce and crowd funding kind of thing. So he wants to spend some money and expects a site that can grow unlimited.

背景知识:我的一个客户正在向我询问一个web应用程序的报价。我不能详细说明,但这是电子商务和众筹之类的东西。所以他想花一些钱,并期望一个网站可以无限增长。

I plan to build it with Zend Framework 2 and MySql. My problem is that I have no experience with large scale web apps. I read everywhere: No problem, just start the project and if it grows to large then you can react on it and add caching, clustering etc.

我计划用Zend Framework 2和MySql来构建它。我的问题是我没有使用大型web应用的经验。我到处都读到:没问题,只要启动这个项目,如果它变得很大,你就可以对它做出反应,添加缓存,集群等等。

But is this really true, or do I have to add some scalability mechanisms from the start? Cloud servers (Amazon EC2) for example have a different approach for the file system. Is it possible to switch later? Or what about load balancing? I get problems with session handling, or not? And what about MySql? Or better start directly with a NoSql approach?

但这真的是真的吗?还是我必须从一开始就添加一些可扩展性机制?例如,云服务器(Amazon EC2)对文件系统有不同的方法。以后可以换吗?或者负载平衡呢?会话处理有问题吗?MySql呢?或者最好直接从NoSql方法开始?

So my current plan is:

所以我现在的计划是:

  • Step 1: Build the web application normally with ZF2 and MySql.
  • 步骤1:使用ZF2和MySql正常构建web应用程序。
  • Step 2: Add caching like memcache and opcode
  • 步骤2:添加缓存,如memcache和opcode
  • Step 3: MySql cluster or NoSql or load balancing or cloud server??
  • 第三步:MySql集群还是NoSql、负载均衡还是云服务器?

UPDATE:

更新:

Ok, I know that my question is a little too broad. So I try to track it down to a few specific questions:

我知道我的问题有点太宽泛了。所以我试着找出一些具体的问题:

  • Better start directly with a cloud server?
  • 最好直接使用云服务器?
  • Can a cloud server grow unlimited?
  • 云服务器能否无限成长?

2 个解决方案

#1


2  

Your plan:

你的计划:

Step 1: Build the web application normally with ZF2 and MySql.
Step 2: Add caching like memcache and opcode
Step 3: MySql cluster or NoSql or load balancing or cloud server??

Here is my suggestion:

这是我的建议:

Step 1: Build the web app on CodeIgniter with MySQL (lighter, and faster than ZF2 with MySQL)
Step 2: Do memchace, opcode and don't forget phpfpm 
Step 3: Use Amazon EC2 and use their Load Balancing features to load balance between servers.

#2


2  

Scaling is a complicated matter and different projects have different needs. I recently read a good book about scaling PHP applications. Maybe this can help you: https://leanpub.com/scalingphp

扩展是一个复杂的问题,不同的项目有不同的需求。我最近读了一本关于扩展PHP应用程序的好书。也许这可以帮助您:https://leanpub.com/scalingphp

Some tips from the book

书中的一些技巧

  • Load balancer for incoming requests
  • 用于传入请求的负载均衡器
  • 1 Mysql master server for writes and x mysql slave servers for reads (if the master goes down a salve server can be promoted
  • 1个Mysql主服务器用于写操作,x个Mysql从服务器用于读操作(如果主服务器宕机,可以升级一个salve服务器)
  • Use a session storage I think the book recommended Reddis (not sure, it's a few weeks back)
  • 使用会话存储我认为这本书推荐的Reddis(不确定,这是几周前的事)
  • Run Nginx instead of Apache
  • 运行Nginx而不是Apache

And on a personal note:

我个人认为:

  • It's maybe about taste but I would recommend Laravel as a PHP Framework, it's lighter than ZF and (again taste..) more elegant.
  • 它可能是关于味道的,但是我推荐Laravel作为一个PHP框架,它比ZF更轻,(再一次的味道)更优雅。

For now I don't recall more from the book, but if you can't get enough information please contact me by e-mail and I will look it up.

现在我记不太清书中的内容了,但是如果你找不到足够的信息,请通过电子邮件联系我,我会查的。

Do I have to concern about scaling from the very start or is it easy to add these technologies like load balancing and session storage later?

我是否需要从一开始就考虑扩展,或者以后添加诸如负载平衡和会话存储之类的技术是否容易?

What I Learned from the book is that in their case (Twitpic) the scaling started after the project became to big and experienced a lot of down time. In my opinion it's a good thing to think about what scaling steps you want to take. A dedicated (My)SQL server or load balancer can be scaled when your project requires scaling. But when your planning to use a session storage service I would recommend to start using it from the start so you don't have to rewrite code at the moment scaling up is required. Also some session storage services store as much information as possible in the RAM which lowers execution time.

我从这本书中学到的是,在他们的例子(Twitpic)中,当项目变得庞大并经历了大量的停机时间后,规模开始扩大。在我看来,考虑一下你想要采取哪些扩展步骤是一件好事。当您的项目需要扩展时,可以扩展专用的SQL服务器或负载均衡器。但是当您计划使用会话存储服务时,我建议您从一开始就开始使用它,这样您就不必在需要扩展时重写代码。还有一些会话存储服务在RAM中存储尽可能多的信息,这降低了执行时间。

Also when your setting up the server I would say start with Nginx it's uses less resources than Apache.

同样,当你设置服务器时,我会说从Nginx开始,它使用的资源比Apache少。

#1


2  

Your plan:

你的计划:

Step 1: Build the web application normally with ZF2 and MySql.
Step 2: Add caching like memcache and opcode
Step 3: MySql cluster or NoSql or load balancing or cloud server??

Here is my suggestion:

这是我的建议:

Step 1: Build the web app on CodeIgniter with MySQL (lighter, and faster than ZF2 with MySQL)
Step 2: Do memchace, opcode and don't forget phpfpm 
Step 3: Use Amazon EC2 and use their Load Balancing features to load balance between servers.

#2


2  

Scaling is a complicated matter and different projects have different needs. I recently read a good book about scaling PHP applications. Maybe this can help you: https://leanpub.com/scalingphp

扩展是一个复杂的问题,不同的项目有不同的需求。我最近读了一本关于扩展PHP应用程序的好书。也许这可以帮助您:https://leanpub.com/scalingphp

Some tips from the book

书中的一些技巧

  • Load balancer for incoming requests
  • 用于传入请求的负载均衡器
  • 1 Mysql master server for writes and x mysql slave servers for reads (if the master goes down a salve server can be promoted
  • 1个Mysql主服务器用于写操作,x个Mysql从服务器用于读操作(如果主服务器宕机,可以升级一个salve服务器)
  • Use a session storage I think the book recommended Reddis (not sure, it's a few weeks back)
  • 使用会话存储我认为这本书推荐的Reddis(不确定,这是几周前的事)
  • Run Nginx instead of Apache
  • 运行Nginx而不是Apache

And on a personal note:

我个人认为:

  • It's maybe about taste but I would recommend Laravel as a PHP Framework, it's lighter than ZF and (again taste..) more elegant.
  • 它可能是关于味道的,但是我推荐Laravel作为一个PHP框架,它比ZF更轻,(再一次的味道)更优雅。

For now I don't recall more from the book, but if you can't get enough information please contact me by e-mail and I will look it up.

现在我记不太清书中的内容了,但是如果你找不到足够的信息,请通过电子邮件联系我,我会查的。

Do I have to concern about scaling from the very start or is it easy to add these technologies like load balancing and session storage later?

我是否需要从一开始就考虑扩展,或者以后添加诸如负载平衡和会话存储之类的技术是否容易?

What I Learned from the book is that in their case (Twitpic) the scaling started after the project became to big and experienced a lot of down time. In my opinion it's a good thing to think about what scaling steps you want to take. A dedicated (My)SQL server or load balancer can be scaled when your project requires scaling. But when your planning to use a session storage service I would recommend to start using it from the start so you don't have to rewrite code at the moment scaling up is required. Also some session storage services store as much information as possible in the RAM which lowers execution time.

我从这本书中学到的是,在他们的例子(Twitpic)中,当项目变得庞大并经历了大量的停机时间后,规模开始扩大。在我看来,考虑一下你想要采取哪些扩展步骤是一件好事。当您的项目需要扩展时,可以扩展专用的SQL服务器或负载均衡器。但是当您计划使用会话存储服务时,我建议您从一开始就开始使用它,这样您就不必在需要扩展时重写代码。还有一些会话存储服务在RAM中存储尽可能多的信息,这降低了执行时间。

Also when your setting up the server I would say start with Nginx it's uses less resources than Apache.

同样,当你设置服务器时,我会说从Nginx开始,它使用的资源比Apache少。