3

When uploading a new DLL for a large web application (dll is around 1mb) IIS throws an error because the DLL is 'in-use', meaning the website is down while the DLL is being uploaded. Is there a way to stop this behaviour?

Also, although I am using Web Applications, not Web Sites, whenever I upload a new DLL it still takes a while for IIS to restart after a fresh upload. I thought this wait was generally only for websites as they need to be compiled by IIS, not Web Applications?

Kev
  • 118,037
  • 53
  • 300
  • 385
izip
  • 2,036
  • 5
  • 22
  • 31

2 Answers2

2

You can use AAR together with some Powershell scripting to deploy with zero downtime in the same machine.

Basically you set 3 sites up . One listening to the requests, passing them to ARR, which redirects them to one of the other 2 sites. Only one of these 2 sites is active at a time.

When deploying, you copy the new files to the stopped site, warm it up, and then tell ARR to start forwarding the requests to this node, at which point you can take the site with the old code offline.

This script pretty much automates this process. It assumes the following file / site / webfarm structure:

File Strcuture

  • C:\PATH_TO_YOUR_CODE\$projectName (This folder holds the files to be deployed)
  • C:\PATH_TO_YOUR_CODE\$projectName-Green (Can be empty to start with - deployment files will be copied here when activating this node)
  • C:\PATH_TO_YOUR_CODE\$projectName-Blue (Can be empty to start with - deployment files will be copied here when activating this node)

IIS Sites

  • "$projectName" (ARR Site) Running
  • "$projectName-Green" (Balanced Site Green) Stopped
  • "$projectName-Blue" (Balanced Site Blue) Stopped

Web Farms

  • "$projectName-Farm"
  • "$deploymentBlueNodeAddress" Unavailable
  • "$deploymentGreenNodeAddress" Unavailable
Yosoyadri
  • 551
  • 5
  • 8
  • This 100x. Blue green deployment is the way to go. [I wrote a tutorial on blue green deployment in IIS with ARR here.](https://kevinareed.com/2015/11/07/how-to-deploy-anything-in-iis-with-zero-downtime-on-a-single-server/) – kavun Nov 08 '15 at 06:08
2

As soon as you make a change such as this you've effectively changed a dependency. The site will need to be recompiled in ASP.NET's shadow copy folders.

Update:

Based on your comment: What if someone was buying and item in an e-commerce site at the same time new updates were pushed out? Its one of my bug bears of .NET (one thing I miss about php was easily uploading PHP files without the hassle)

If you've only got a single server then you need to plan your updates and give some advance warning that the site will be unavailable due to an upgrade. There's a feature in ASP.NET called App_Offline.htm. It's a special page which when present in your application will cause ASP.NET to render its contents no matter which page is requested. You can use this to display a message explaining to users that the site is offline for maintenance. You can read more about it here on Scott Guthrie's blog.

It's not unreasonable to approach site upgrades this way because it's a mechanism to perform a site update in a single atomic step and provided you give users plenty of advance warning they won't mind (and perhaps do this at a time when your traffic is at a typical low point) .

You mention that in PHP you wouldn't have this problem. Actually, if you're updating anything more that a couple of non-related pages then you should be preventing users from accessing the site during upgrades as a matter course.

Say you're updating five or six pages all loosely related - perhaps as part of an e-commerce application. During the upload process you deploy the first page and it gets served to a user. One of the changes you made to this page was to add a a new field to a form. The page posts back to a another PHP script that uses this field. Two scenarios exist:

  1. The postback page is new and is still in your upload queue. This breaks the newly uploaded script because when a user clicks submit there is nothing to submit to.

  2. The postback page already exists but hasn't been updated. This page writes the form post fields to a database. You've added this new field to the database but it's a mandatory field and can't be null. Your no-yet-updated postback script tries to update the DB but an error is raised because the new field isn't in the postback form's INSERT statement and thus is null causing a NOT NULL constraint violation.

I could go on. If your site provides more than just a trivial amount of functionality then you should go offline for ALL updates to ensure that ALL you're updated code is deployed in a single atomic update.

Kev
  • 118,037
  • 53
  • 300
  • 385
  • 1
    So there is no way around this? It seems like a big flaw to me. What if someone was buying and item in an e-commerce site at the same time new updates were pushed out? Its one of my bug bears of .NET (one thing I miss about php was easily uploading PHP files without the hassle) – izip Jan 15 '11 at 22:16
  • Thanks Kev. However, I disagree to a point. If you are making a change to 3 php files you can quickly upload these quickly without any issues. If you did the same to even 1 *.cs file you have to recompile the whole app and upload. I have known of shared hosting providers to cache dlls and dlls only get re-read by IIS when you force an app pool restart. I thought this might be an easy option but maybe not. The other thing I could do is upload to a temp folder then login to the server and copy the DLLs. Either way when maintaining several websites its a little annoying. – izip Feb 10 '11 at 13:12
  • @izip: how about uploading to a second site? Then, once it's all uploaded, you switch which physical folders the two sites point to. – John Saunders Feb 10 '11 at 13:19
  • Again another option, but not exactly a great work around. I appreciate your suggestions and realize that for most this is a non-issue. However for me I regularly maintain / update 20+ projects each week. – izip Feb 17 '11 at 15:49
  • @izip - having taken the time to explain why this is the way it is and to explain why it can also be problematic uploading multiple PHP or ASP scripts (i.e. at some point during the deployment not all the scripts are at the same build level until the upload is complete; you have the potential for broken dependencies because you left your site live during deployment)....you could at least upvote...or even accept, because it is technically the correct answer? even though you don't like it :) – Kev Feb 17 '11 at 18:13