Getting ASP.NET Core Applications Production Ready in Elastic Beanstalk (IIS 10)

By default, there are several settings in IIS which would cause issues in Production for high-load applications.

(Steps below were tested on Win 2016, IIS 10, running ASP.NET Core 2.0.1 with .NET Framework 4.7.1)

Firstly, IIS is configured to shut down a process after x minutes of inactivity. The default setting is 20 minutes. The setting is called “Idle Time-Out (mintues)”.

In a web farm scenario, for one reason or another, you can have a node that did not receive a request in a span of 20 minutes. Once the node does receive the request, it will have to spin up the ASP.NET Core app, which takes some time. The user will then have to wait for the spin up to complete before receiving the response. This results in sub-ideal user experience.

To disable the timeout run this command:

(You can add these commands as .configs in your .ebextensions)

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.processModel.idleTimeout:00:00:00 /commit:apphost

Also, IIS will recycle an app pool after very 29 hours (1740 minutes). To disable the auto-recycle, run this command:

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:00:00:00 /commit:apphost

Then, we need to set the start mode to “AlwaysRunning” instead of the default “OnDemand”

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.autoStart:"True" /commit:apphost

%systemroot%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.startMode:"AlwaysRunning" /commit:apphost

When deploying a new version of the app, IIS or ElasticBeanstalk will NOT automatically warm up or invoke your application. For this to happen you need to either automatically call each EC2 node and warm it up, or you can use IIS Application Initialization (https://docs.microsoft.com/en-us/iis/configuration/system.webserver/applicationinitialization/)

By default, EC2 nodes do not have this feature enabled. To enable the feature, install it via:

powershell.exe -Command "Install-WindowsFeature Web-AppInit"

Then, in you web.config, specify the path which should be called to warm up the application. In this example, warmup action is called on the Home controller.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <system.webServer>
     <applicationInitialization>
       <add initializationPage="home/warmup" />
     </applicationInitialization>
   </system.webServer>
</configuration>

And here’s the controller/method:

public class HomeController : Controller
{
    [HttpGet]
    public async Task Warmup()
    {
        // do warmup
        // kick out requests not coming from 127.0.0.1 or ::1
    }
}

In the warmup method (action), I strongly recommend you check if the request is coming from ::1 or 127.0.0.1, and if it is not, disallow the warmup. This will prevent from someone doing a warmup (which is often expensive) without having the authorization to do so. Since the IIS Application Initialization module is doing the invocation of your warmup method, the request will come from 127.0.0.1

Lastly, you need to set “Preload Enabled” to “True” for all your sites via this command:

%systemroot%\system32\inetsrv\AppCmd.exe list app /xml | %windir%\system32\inetsrv\appcmd set app /in /preloadEnabled:True

And there you have it, your ASP.NET Core applications are now production ready!

Idea: Inconspicuous body cams for athletes

When watching a hockey game it would be cool if you can see the game from the point of view of the players. If one could design a small camera that is of no trouble to the wearer and that has great image quality then during the game the broadcaster can cut to any of those cameras to show a different angle.

If watching online, I could select the player from a list below the video player widget and watch the game from that player’s point of view.

Idea: Control (and rent) Drones Remotely

When travelling to Iceland and Khao Yai national park in Thailand I noticed an emerging trend: people bringing drones with them on a trip.

Drones are not cheap. They start at 1k USD plus a good camera will run you another grand, at least.

What if there was a way to remotely control a drone, that is rented? For example, one could establish a company that has several physical drones deployed in interesting parts of the world – could be national parks, nature reserves, near volcanoes, etc.

Then, via a website one can book a time slot to fly a drone in any of those locations. The flying time may be limited to 15 mins max, for example. After downloading the remote control app,  I can remotely fly a drone miles away in a different continent – in the comfort of my own home. I would pay premium for the experience.

 

Idea: Allow drones to recharge from power lines

There are miles and miles of high voltage power lines running all throughout Canada – from city to city and province to province. Wouldn’t it be cool if delivery drones and such had an ability to recharge by hovering and attaching a charge cable to an exposed high voltage power line. I’m sure the voltage / amperage can be stepped down to something that a drone can use.

Drones, when detecting low battery, would use a map to find the closest power line and then “sit” on a wire like a bird until recharged. This way travelling over longer distances problem can be solved.

Idea: Dual Exhaust – one for city and one for highway use

The main problem with “performance” or louder than stock exhausts is that they are annoying or no fun on the highway. Your throttle is pretty much constant on the highway and the elevated noise coming from the exhaust gets annoying quickly. You can sound proof your car but that can run you into $ 1k+ easily.

Another solution is to have two mufflers with an ability to choose though which one the exhaust gases will flow. One muffler can be louder so you can use it in the city. Once you go on the highway you can flip a switch and activate the quieter muffler.

A performance muffler is around $100. Plus piping – another $30 or so. The ability to switch between the two? Throw in another $100. Many sports cars or sporty looking cars come with dual mufflers anyhow. So it’s just adding the switch.

C# – Lookup nested field in ExpandoObject at runtime

say you have a JSON object like this

{
    home: {
        garage: {
            bike: {
                make: "honda"
            }
        }
    }
}

in C# you’ve loaded the JSON into an ExpandoObject like this:

dynamic json = JsonConvert.DeserializeObject("json text above...");

to lookup a field, you can just do

var make = json.home.garage.bike.make; // "honda"

which is just great.

but what if you need to lookup fields whose names you do not know at compile time?

with the little helper i wrote you can do this:

var fieldName = "home.garage.bike.make"; // this will be resolved at runtime

var make = json.GetField(fieldName);

==================

public static object GetField(this ExpandoObject expandoObject, string path)
{
    if (expandoObject == null)
        return null;

    var pathSegments = path.Split('.');
    var lastPathSegment = pathSegments[pathSegments.Length - 1];

    var cursor = (IDictionary)expandoObject;

    for (int i = 0; i < pathSegments.Length - 1; i++)
    {
        var pathSegment = pathSegments[i];

        cursor = (IDictionary)cursor[pathSegment];
    }

    object result = null;

    cursor.TryGetValue(lastPathSegment, out result);

    return result;
}

Cheers

Idea: Bring some of Aereo home

I like the idea of having a remote antenna. It’s like having my own antenna but with a very long cord. In actuality it IS a very long cord. I’m connected to the internets via my cable provider who via underground cables reaches out to wherever. I don’t see how having an antenna with 5 foot or 10,000 foot cord makes a difference.
Having Aereo doing the recording on their servers and charging me to access the recordings does not pass the smell test for me. It does seem a bit like re-broadcasting.
Why not do this: I would still like Aereo to house the antenna (or several antennas) for me. They can aim it, make sure it gets reception, etc. I have no problem paying for that.
Then, Aereo can sell a small Android (or whatever OS) powered box that connects to the internets. It will reach out to the remote antenna but will record onto a local storage (memory card, etc) or NAS. The box will also grab metadata (show title, cast, etc) about what’s being recorded. The box can also broadcast locally via the local network so you can watch on your iPad for example. So it will act as a DNLA as well.
All the recorded content will be nicely presented and organized, same as on Aereo’s website You can connect the box to the TV or access it from iPad or your computer.
Seeing how android tv boxes are sold for ~$100 these days producing such a box may not be that expensive. The price can be subsidized so that the consumer does not have to fork out too much to get the box. The cost can be rolled into the monthly subscription fee.
The difference from current model to me would that Aereo’s would strictly provide an antenna hosting service. They would simply transmit the whatever signal antenna is receiving via a long cable (internet) onto my receiver.