meow
meow

Reputation: 307

Autoscale Magento in the cloud

I have just entered into the world of e-commerce, and I am trying to get my Magento website up and running.

I am using AWS cloud for hosting my website. I am trying to use an architecture, where I can run multiple servers connected to a single DB server. Specifically, I want to use an AWS Auto scaling group along with ELB to start multiple EC2 instances, during high load. There is only one Mutli AZ RDS Database instance.

As initial trials, I tried creating 2 ec2 instances, and installed magento on both of them. I have used same RDS DB for both of them. But as is turns out, magento stores the base url of webserver in the database itself. Which means, I can only store one base url of magento website running one particular server.

To be precise magento stores base url in table core_config_data in column 'path' where row values ares "web/unsecure/base_url" and "web/secure/base_url", and the column 'value' for corresponding row specifies the url address of magento installed web server. My question is how can I use multiple server using EC2 auto scaling, if magento permits only one server address in the base url.

Here's a partial view of the table with 2 rows -

config_id   scope     scope_id    path                      value   
5           default   0           web/unsecure/base_url     http://server1.com/magento/
6           default   0           web/secure/base_url       http://server1.com/magento/

Are there any other known methods to somehow use horizontal scaling during heavy load conditions in Magento.

Upvotes: 1

Views: 2983

Answers (3)

Andrew Howden
Andrew Howden

Reputation: 307

I've had a rather large amount of success modifying the Magneto to be a beanstalk package. The steps (loosely) were:

  1. Install GIT locally
  2. Install AWS Command line tools
  3. Install AWS Beanstlalk Command Line
  4. Build module to upload image to s3 everytime it's uploaded in magento
  5. Utilize OnePica's Magneto Extension
  6. Use Amazon's REDIS Cache for caching data
  7. Use RDS for database
  8. Use Route53 for routing &
  9. Use cloudfront for image, js & CSS Distro

Couple of drawbacks to AWS

  1. Customizing magneto to look for things is a pain in the ass. As we speak I'm trying to get it to keep sessions persistent between EC2 instances as the loadbalancer chops it up.
  2. Everytime you need to modify Magento in any way it's a git commit, (then we test locally, via a seperate beanstalk instance) and then push to production.

Short of that it's been fairly stable. We're not hitting high numbers yet, though.

Upvotes: 1

Malachy
Malachy

Reputation: 1590

I don't think load balancing works like that.

You need a load balancer that receives the requested URL and then passes it off to one of the servers running Magento - so I think you would pass the same url to both servers anyway, no?. I do not know how to do it.

You are trying to set up a very complicated system.

You could look to override some functions if you want to have different values for secure and non-secure urls. Try reading this code to get you started:

//file app/code/core/Mage/Core/Model/Store.php
//class Mage_Core_Model_Store
//function getBaseUrl()
//function getDistroServerVars()

//file app/code/core/Mage/Core/Model/Url.php
//class Mage_Core_Model_Url
//function getBaseUrl()

//file app/code/core/Mage/Core/Controller/Request/Http.php
//class Mage_Core_Model_Http
//function - I don't know, any of them, none of them

and look at any files with the string 'substDistroServerVars' in them or isDirectAccessFrontendName might expose something. getDistroServerVars is discussed at the end of this great article by the almighty Alan Storm.

But I don't think that is the real answer - for the real answer skip to the links at the end of this tedious monologue.

If this is your first foray into Magento and you really think you are going to get the volume of traffic into your shop that requires load balancing over two servers then you can afford, *must afford**, third party hosting and get professionals with many many many man years of experience running Magento on heavy loads across multiple servers. You will also want to hand off (at least) the images to a CDN.

*I mean, if your shop has that high a volume then it has a high revenue and you should invest that revenue in keeping your shop running: professional hosting with 24/7 support. Otherwise downtime will be expensive and a long implementation will mean lost revenue.

*If you are just trying this out for fun and to learn something about setting up Magento on multiple servers then I recommend two things:

1) Practice getting Magento running on one server first - and optimsing for volume there (caching, compilers, DB tuning, log file analysis, flat tables, cron jobs, CDNs, possibly combined JS and CSS, web server tuning and getting the headers right, possibly a full page cache and a sprinkling of Redis) - because that isn't a trivial list on one server never mind two + DB server and ELB.

And 2) practice getting Apache or nginx to serve load balanced content with your ecommerce SSL certificate in place. Only then should you try to join the two systems. Be prepared to spend many months on this - including figuring out Seige, AB or jmeter for simulated load testing.

But if you really want to get the AWS ELB set up here are a few excellent resources to get you started - particularly the detailed tutorial by Adrian Duke (first link) - pay great attention to the details in the last section of that article subtitled 'Magento', that may be the answer to your question.

Getting and scaling Magento in the cloud by Adrian Duke

Using AWS Auto Scaling with an Elastic Load Balancer cluster on EC2 (actually a WordPress install, not Magento, but Mr Shroder knows his Magento)

Running Magento in an AWS Environment (All hail Alan Storm)

Upvotes: 1

Ashley Swatton
Ashley Swatton

Reputation: 2125

Normally you put a load balancer in front of the nodes to distribute the load and each node is configured to use the same base_url. MySQL replication can be used if you want multiple db servers but I have never found the need to do this. Not used amazon ec2 with magento but have similar setup in a dedicated server environment with two nodes, one db server, load balancer, and shared media.

Diagram here is useful, especially with the shared storage for media, your going to need to do something like this. http://www.severalnines.com/blog/how-cluster-magento-nginx-and-mysql-multiple-servers-high-availability

Also, I found amazon seems to provide Elastic Load Balancing which is what your after I think. http://aws.amazon.com/documentation/elasticloadbalancing/

Upvotes: 0

Related Questions