If you are using AWS elastic load balancer to scale your system, you may find that it is a good solution to offload SSL termination from your servers.
Why Should You Offload SSL Termination?
HTTPS is an encrypted protocol, and encryption required high CPU utilization to perform the needed mathematical computations.
Since most web applications are CPU bounded, you should avoid processing SSL at your servers.
Why AWS Elastic Load Balancer (or Any other LB) Is a Great Candidate?
In order to perform load balancing, the load balancer must decrypt the traffic and read its content. This is done by placing your certificate on the load balancer.
If you consider the network between your LB and your servers to be secure, you should prefer to avoid re-encryption of the traffic, and keep it clear.
How Can I Make Sure Traffic is Actually Secured?
In some cases, you want all your users to use HTTPS as an encrypted channel in order to keep your users privacy and avoid eavesdropping and injections.
In these cases you want to catch traffic that did not use HTTPS before being terminated in the LB and redirect it to HTTPS. This can be done by evaluating by the X-Forwarded-Proto server field in your .htaccess or Apache configuration:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Bottom Line
A careful design can help you get more out of your web servers
Keep Performing,
Moshe Kaplan
News, Personal view and perspective of the software performance field, cloud computing and industry based on my experience
Showing posts with label Amazon Load Balancing. Show all posts
Showing posts with label Amazon Load Balancing. Show all posts
Jan 16, 2015
Jul 14, 2014
Keep Your Website Up and Running During an Upgrade
All of us want to have our website up and running.
However, upgrading a software version requires downtime (even if it minimal).
What should we do?
The answer is simple: follow the following process and gain a highly available system based on load balancing and session off loading, as well as a no downtime procedure to upgrade your system.
Keep Your Site Up and Running @ AWS
However, upgrading a software version requires downtime (even if it minimal).
What should we do?
The answer is simple: follow the following process and gain a highly available system based on load balancing and session off loading, as well as a no downtime procedure to upgrade your system.
Keep Your Site Up and Running @ AWS
- Place more than a single web instance behind a load balancer. The Elastic Load Balancer (ELB) will be fine for that.
- Make sure you are using session offloading in your system implementation.
- Install elbcli on your machine sudo apt-get -y install elbcli
- Create a credentials file /var/keys/aws_credential_file and secure it sudo chmod 600 /var/keys/aws_credential_file
AWSAccessKeyId=AKIAblablabla
AWSSecretKey=blablablablablablablablabla - Upgrade the servers one after the another.
- Before upgrading a server, take it out of the ELB
sudo elb-deregister-instances-from-lb MyLoadBalancer --instances i-4e05f721 --aws-credential-file=/var/keys/aws_credential_file - And after completing the server upgrade take it back in.
sudo elb-register-instances-with-lb MyLoadBalancer --instances i-4e05f721 --aws-credential-file=/var/keys/aws_credential_file
Bottom Line
A simple process and careful design will keep you system up and running.
Keep Performing,
Jun 19, 2010
At My Command Unleash Version!
Click on the post title to read the full post and the comments.
As you may know I'm a big fun of Continuous Integration, a.k.a CI, (running every trunk commit with some unit tests and integration tests, finding that you ruined the build and earning the blame T-shirt is such a good way to start the morning :-).
Cool things you can do with CI
However, today's CI is much more from just running several tests. These days you can do almost everything with it:
Cloud computing is basically about obtaining on demand resources through API (the GUI is a fancy stuff that can be useful but is not really a must). Therefore, you can use CI to automate every step in your testing, upload to production and rollback when needed. Some of the scenarios are:
Industry Best Practices
According to Amazon (see Jinesh Varia, Technology Evangelist @Amazon Web Services document), CI and automation is the best practice to manage your cloud environment:
What CI to choose?
There are many CI products in the market, some of them are open source and other are commercial. Here are some of leading tools, thanks to Alon Nativ advice:
Bottom Line
Now after going over the details, I recommend you to:
Moshe Kaplan
As you may know I'm a big fun of Continuous Integration, a.k.a CI, (running every trunk commit with some unit tests and integration tests, finding that you ruined the build and earning the blame T-shirt is such a good way to start the morning :-).
Cool things you can do with CI
However, today's CI is much more from just running several tests. These days you can do almost everything with it:
- Get your latest version from trunk.
- Build the version.
- Launch a new virtual machine based on a predefined image or by installing it almost from scratch.
- Install the version on the new machine.
- Run smoke tests to provide an instant validation of the code stability.
- Run nightly builds to carefully check that the version is clean.
- Run stress tests to validate capacity and long multiple days tests to validate memory leaks.
- Notify key players with the results.
Cloud computing is basically about obtaining on demand resources through API (the GUI is a fancy stuff that can be useful but is not really a must). Therefore, you can use CI to automate every step in your testing, upload to production and rollback when needed. Some of the scenarios are:
- Performing Software Upgrade: Launching a new instance, installing the latest software version and creating an Image (AMI in AWS).
- Launching an entire new integration environment that is identical to the production environment and check its functionality as well as its correspondence with the non functional requirements.
- Launching a new environment for marketing needs.
- Managing your new version upload, by creating a script that will prepare new servers, upgrade your database servers (or RDS), add new application and web servers to the load balancer farms, and finally will remove the old server and shut them down.
- Implement Failover scenarios (DRP)
Industry Best Practices
According to Amazon (see Jinesh Varia, Technology Evangelist @Amazon Web Services document), CI and automation is the best practice to manage your cloud environment:
- Create a management server (like CruiseControl or regular CRON jobs).
- Create a build-test-deploy cycle script using the chosen management server that will generate:
- New AMI
- Deploy new servers based on these AMI
- Add these servers to existing load balancer
- Attach elastic IPs
- Generate static files to S3 and CloudFront
- Generate new queues and notifications using SQS and SNS
- Remove old servers and unneeded AMIs
What CI to choose?
There are many CI products in the market, some of them are open source and other are commercial. Here are some of leading tools, thanks to Alon Nativ advice:
- CruiseControl: a leading open source product with dozens of plugins and 3rd parties.
- Apache Continuum: an open source product with many features.
- Final Builder: a commercial and major tool in the market with great visual interface and many built in scripts and API
- JetBrains TeamCity: a commercial tool with a built in integration to Amazon AWS.
Bottom Line
Now after going over the details, I recommend you to:
- Design your cloud environment.
- Design your baseline AMIs/Images.
- Design your upgrade, rollback and test-build-deploy scripts based on these basic AMIs.
- Implement them using your chosen Continuous Integration tool.
- Roll it out to production.
Moshe Kaplan
Dec 19, 2009
Load Balacing Support in Dynamic Environments
Hi,
The Mission
These days we face a challenging task: designing a very large system of scalable instances. Each of these instances may be in a different geographic location, and many of them are on demand instances that are being started and shutdown instantly.
Another requirement in this system that a given client will be direct to a defined instance, due to system restriction (a round robin is not an option is this case).
One Step Further
Since the number of IP addresses in the internet is limited, we would like to use as few as possible Public IP addresses. This can be done using a load balancer or a proxy.
In the current state we would like to avoid using hardware load balancers in order to keep initial fixed costs minimal, but we may consider to use them in the future.
Is Amazon Cloud Load Balancer Service (AWS) is an Option?
AWS EC2 instances is a feasible option for on demand instances hosing. However, AWS charges $0.025 per a single load balancing rule per hour (+traffic). Therefore, it can be used, but for a large number of rules (>7) or high traffic, better solutions can be found in the market.
So What Can Be Done?
We left with software load balancers. The major ones Apache mod_proxy and HAProxy. Supporting large number of instances behind the load balancer can be done in one of the following two options:
However, Willy Tarreau, HAProxy author who kindly provided this hint for me, recommends that you avoid the second part (rewriting) because :
1) it requires good regex skills which sometimes makes the configs hard
to maintain for other people
2) rewriting URIs in applications is the worst ever thing to do, because
they never know where they are mapped, and regularly emit wrong links
and wrong Location headers during redirections.
Willy Tarreau also advices that the best thing to do clearly is to correctly configure your application to be able to respond with the real, original URI. Remapping it can be used
as a transitional setup in order to ease a graceful switchover, though. Bottom line: Pros: No DNS configuration and fully scalable solution, with no dependence on DNS replication. Cons: CPU Consuming and error prone declarations.
So, What to Choose?
The answer is based on your needs, and your believe in your people regex capabilities. We made our choice.
Keep Performing,
Moshe Kaplan. Performance Expert.
The Mission
These days we face a challenging task: designing a very large system of scalable instances. Each of these instances may be in a different geographic location, and many of them are on demand instances that are being started and shutdown instantly.
Another requirement in this system that a given client will be direct to a defined instance, due to system restriction (a round robin is not an option is this case).
One Step Further
Since the number of IP addresses in the internet is limited, we would like to use as few as possible Public IP addresses. This can be done using a load balancer or a proxy.
In the current state we would like to avoid using hardware load balancers in order to keep initial fixed costs minimal, but we may consider to use them in the future.
Is Amazon Cloud Load Balancer Service (AWS) is an Option?
AWS EC2 instances is a feasible option for on demand instances hosing. However, AWS charges $0.025 per a single load balancing rule per hour (+traffic). Therefore, it can be used, but for a large number of rules (>7) or high traffic, better solutions can be found in the market.
So What Can Be Done?
We left with software load balancers. The major ones Apache mod_proxy and HAProxy. Supporting large number of instances behind the load balancer can be done in one of the following two options:
- Pre register a large number of DNS addresses (sub domain) and associate them with the load balacner IP. The load balancer will simply redirect the request to the defined instance, based on the a simple rule in the load balancer. For example: http://instN.foofarm.com Pros: simple. Cons: not fully dynamic, requires additional DNS registration once in a while to keep up with the application growth.
- Performing ProxyPass in the Load balancer: Every request will include in its path an instance identification for example: http://foofarm.com/instN/. This method does not require mass DNS declarations, but it requires specific definitions in the load balancers that may be more CPU consuming. In Apache the definition is pretty trivial, however, this product is less scalable from HAProxy. In HAProxy the task can be done as well based on a two phases: switching to the server and rewrite the URI:
In order to switch to the server, you have to use ACLs to match the path,
then a use_backend directive to select a server farm ("backend"). Your
farm may very well support only one server if you want.
Then in this "backend", you can use a rewrite rule ("reqrep") to replace
the request line.
This would basically look like this :
frontend xxx
acl path_mirror_foo path_beg /mirror/foo/
use_backend bk_66 if path_mirror_foo
backend bk_66
reqrep ^([^: ]*\ )/instN/\(.*\) \1/\2
balance roundrobin
server srv66 192.88.77.66:80
However, Willy Tarreau, HAProxy author who kindly provided this hint for me, recommends that you avoid the second part (rewriting) because :
1) it requires good regex skills which sometimes makes the configs hard
to maintain for other people
2) rewriting URIs in applications is the worst ever thing to do, because
they never know where they are mapped, and regularly emit wrong links
and wrong Location headers during redirections.
Willy Tarreau also advices that the best thing to do clearly is to correctly configure your application to be able to respond with the real, original URI. Remapping it can be used
as a transitional setup in order to ease a graceful switchover, though. Bottom line: Pros: No DNS configuration and fully scalable solution, with no dependence on DNS replication. Cons: CPU Consuming and error prone declarations.
So, What to Choose?
The answer is based on your needs, and your believe in your people regex capabilities. We made our choice.
Keep Performing,
Moshe Kaplan. Performance Expert.
Subscribe to:
Posts (Atom)