Being engaged in startups, I finally got to the point where you need to be ready to scale the application to N servers for 1M views per day and I began to think how to do this most effectively using Amazon Ec2.
The approximate plan is known to everyone - a server is more powerful for the database and a set of small servers that start / stop as needed depending on the load.
From inexpensive servers, Amazon has no particular choice. Initially, I planned to use
Small Instance for this - this is the option that amazon recommends by default. It has 1.7 GB of RAM, which is pretty comfortable for windows, but only 1 ECU. In practice, 5-8 workflows can be placed in memory, however, they can’t really work at the same time - the core is one and very weak: 1 ECU is just 1 Ghz of one 2007 Xeon core. According to my estimates, the approximate equivalent is a Celeron processor at a frequency of 1.5 Ghz. There is such a server $ 0.12 per hour ~ $ 86 per month, a dozen - $ 860 per month ... It was obvious that this server configuration did not quite answer my tasks.
')
So I decided to try
Micro instance - only 613 MB of memory, but then:
- performance reaches 2 ECU
- it is 4 times cheaper
- can use 64 bit Windows Server 2008 R2 Core platform
Probably many will be interested - why did I choose the x64 system for 613 MB of memory? The arguments are as follows:
- 2008 R2 is a new system, compared to 2008. 2008 is based on Vista, R2 is based on windows 7.
- Improved IIS performance
- Improved OS-level virtualization, which we will use
Server Core is a reduced installation of Windows, without many GUI elements - there is no Internet explorer, usual Explorer and even a taskbar!
Let us analyze the steps for setting up such a server:
1. Install WindowsThere is no Core version in the list of systems offered by default. However, it can be found by searching for the keyword "2008R2":

Having started Micro instance we can connect to it via RDC, where instead of the usual desktop we are met by a bare command line:

After typing the taskmanager, we see that we have 300 MB of memory occupied, the total amount of virtual memory is approximately 1.4 GB. The instance has a single disk of 16 GB in size, of which after installation it is free a little more than 11 GB, which is quite enough for our tasks.
2. Connecting to other cloud computersFirewall in Ec2 (called Security Groups), as usual, allows specified IPs to open the specified ports. In order not to add the IP of each server running manually, you can use the following method — instead of IP, enter the name of the security group (which is shown on the details tab, and looks something like “sg-c45ac45a”) and allow access on all ports.
When creating a new instance, we specify the same Security group and the new instance automatically has access to any other resources of your cloud. My security groups look like this (note the first and last lines added for ms sql):

Accordingly, we successfully execute the following command and connect via internal IP to the main server:
net use z: \\10.20.30.40\C$ /user:Administrator
3. Installing IIS, .NETThe full set of various commands is described in detail by MS on this page -
http://technet.microsoft.com/en-us/library/ee441260(WS.10).aspx , however, in order not to type it all every time I did “regiis. bat ”on the main server. Having launched it on the blade, we perform all the necessary installations (I threw away the FTP server, you can remove a few more functions - experiment):
start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;IIS-ApplicationDevelopment;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementScriptingTools;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;WAS-WindowsActivationService;WAS-ProcessModel
Dism /online /enable-feature /featurename:IIS-ManagementService
Dism /online /enable-feature /featurename:WAS-NetFxEnvironment /featurename:IIS-ISAPIExtensions /featurename:IIS-ISAPIFilter /featurename:IIS-NetFxExtensibility /featurename:IIS-ASPNET
To allow a remote connection to manage IIS, all that remains is to change the key in the registry (run regedit.exe):
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ WebManagement \ Server - the EnableRemoteManagement property is set to 1.
and run the remote control service on the blade instance:
net start wmsvc
We check the connection to IIS from the main server - Connect to server ..., specify the internal IP, Login / Password and save the connection:

It remains to copy the application code, for which I created on the main server copylocal.bat, which copies the latest application sources into a predefined folder using xcopy.
Again, this .bat needs to be run on a blade server.
From the main server we configure iis - we check the use of .net in the application pool, the number of processes - I set 3, since the average size of W3WP.exe is about 100 MB, and after that we successfully open our server in the browser on http: // and its public dns.
The server is ready to work and connect to loadbalancer.
4. ScalingIn order not to do these operations N times, we create the AMI of this instance that already includes all installed applications, network connections and the necessary code. This gives us the opportunity to run exactly the same server with all the necessary software and our code with a few mouse clicks.
The distribution of work between servers can be charged to loadbalancer from amazon, the 1st load balancer for 1 year is offered free of charge.
Updating the server version looks like this:
- we lift a new blade with the old code in the manual mode
- update the code (we have a batch file)
- we check work on http
- we do AMI of the new version
- we multiply the necessary number of servers
- change used servers in load balancing
- shut down old servers - Terminate command
There is also an option to use autoscaling, but I think to tell about it another time.
5. Speed ​​testingUntil recently, I was afraid that there would be unjustified brakes on such a small amount of memory, so it was necessary to check the system under at least some load.
For testing, I used
loadimpact.com and a special controller method that redirect to a random page. The result was quite decent -
here is the report , especially for the cost of this server at $ 21 / month.
A large response time on 10 and 20 clients is explained by the initialization of the application, the swap of unnecessary parts of the system, since the test was started immediately after configuring.
Financial resultsIt is obvious that in the Windows world it is hard to imagine life without a mouse, context menus and GUI to customize anything. However, this was not so difficult. The biggest difficulty was to choose the firewall settings (both Amazon and built into windows) and come up with a simple layout that does not require a lot of effort. I think that with this instruction it is really possible to set up such a server in an hour, and this will give you substantial monthly savings.
My overall impression is that the effectiveness of this configuration in terms of $ 1 is about 3 times higher compared to using the array of small instance. That is, approximately 6 small instances can be safely replaced by 8 micro instances, which in money terms means $ 173 dollars a month instead of $ 516 - more than 4,000 dollars a year.
Useful information1. Getting started for Core -
http://technet.microsoft.com/en-us/library/ee441260(WS.10).aspx .
2. If you closed the console, you can press Ctrl + Alt + End, which is the same as Ctrl + Alt + Del on your computer and run Taskmanager. The "execute" command again allows you to run cmd.
3. To end the session, use the logoff command.
4. Types of Amazon instances -
http://aws.amazon.com/ec2/instance-types/ .
5. Prices for Amazon instances (depending on the data center in which you want to place them) -
http://aws.amazon.com/ec2/pricing/ .
Update (07/26/2011): Stress testing such a server -
http://loadimpact.com/result/ec2-50-19-133-136.compute-1.amazonaws.com/en/random-9ec1ada5c887d3d3c8607ecb740547a2