Posts tagged 'AppHarbor'

22

May 2011

Google App Engine Price Increases - Bad for Small Apps, and No More Free Scaling :o(

At Google IO it was announced that this year that Google App Engine will come out of "preview" and add additional features and an SLA. Sounds great, but it also seemed like a lot of this hype was to try and downplay something else that was changing... the prices. As the service comes out of preview, it needs to be able to sustain itself financially. That means, price increases! (full details here)

The most significant change to me is the shift from charging for "CPU hours" being actual hours worth of CPU cycles (for a "standard" CPU), to being "your app being live for an hour, even if it uses 0 CPU". This is how most of App Engine's competitors work, and actually the reason I always thought Google App Engine's prices were so reasonable for small apps.

The problem with this model is that if you have a very low traffic application (which, let's face it, is how most apps will start out), it costs you almost nothing. In fact, for the few years this blog has been running on App Engine, I haven't paid a single penny. Even on a day I received 50,000 visitors, I didn't break the free quota despite my application being scaled across 4-5 instances for most of the day. My CPU use was so low, it was measure in minutes!. This made App Engine an ideal place for trying out ideas, because it was really cheap. And let's face it, if your idea takes off and it's already hosted on App Engine, you're unlikely to move away, so it was Win/Win, both for you, and Google.

The alternative model, which App Engine is soon to adopt, is that your low-traffic app is being charged just for being "live". This is the reason I've never set anything up on Azure or EC2. It costs you the same if you get 0 visitors in a month, as a single-instance application getting moderate traffic.

This change has another implication for small apps. No more free scaling. Previously, your application could scale out to a number of instances for periods of the day and you could stay within the free quota. Now that the free quota will be only 24 CPU hours, it's impossible for your application to burst out of a single instance without incurring a cost.

Note: The new pricing page lists "Dynamic Scaling" under the free version, however unless you're prepared for your application to be available for less than 24 hours in a day, I don't see how this could possibly be achieved. It's possible this refers to it being possible, though extra charges will apply.

This might not sound like a big deal - competing services already charge like this anyway (and some don't even have free quotas), however for me, this is more significant. I'm a .NET developer by trade. I'm not a huge fan of Java or Python, but App Engine's pricing was so good, it went some way to outweighing the use of .NET. Now that the pricing is the same, it doesn't really make sense as a .NET developer to give up all the benefits of the development environment/frameworks I'm used to using (and the productivity boost I get from them).

My current thinking is to move my apps over to AppHarbor, but once they're written in .NET, Azure and EC2 are probably also possibilities if AppHarbor doesn't work out. First project, this blog!

08

May 2011

Extending MarkdownHelper/MarkdownDeep.NET to support Google Code's Prettify Syntax Highlighter

I'm in the process of rewriting my blog in ASP.NET MVC to move it from Google App Engine to AppHarbor. One of the important changes is that all my articles will be stored as Markdown instead of HTML.

I've blogged previously about the MarkdownHelper class I created and put on NuGet to make using Markdown in views as trivial as typing:

@Html.Markdown(Model.Body)

One thing that I didn't take care of was adding syntax highlighting to code blocks. On this blog I currently use Google Code's Prettify syntax highlighter, and this requires a CSS class be applied to code blocks:

<pre class="prettyprint">
// Code here
</pre>

By default, MarkdownDeep (which my MarkdownHelper uses) doesn't add these classes, so I had to make some changes to support it. I didn't want to build this into MarkdownHelper as it's fairly specific to using this particular syntax highlighter. Instead, I decided to take advantage of partial classes to allow the functionality to be customised without having to modify the MarkdownHelper.cs file added by MarkdownHelper/NuGet.

First I amended the MarkdownHelper class, adding "partial" to the declaration. This was pushed to NuGet as MarkdownHelper 1.2:

public static partial class MarkdownHelper
{
// ...
}

With this done, I loaded my blog in Visual Studio and opened the Library Package Manager, which showed the update and replaced the class with one click. With this done, I then created a new file named "MarkdownHelper.CodeFormatting.cs" alongside "MarkdownHelper.cs" in my Helpers folder. This is where my customisations should go, which will allow MarkdownHelper.cs to be updated by NuGet without affecting the customisations.

As it turned out, customising the code blocks with MarkdownDeep was pretty easy. The class has several extension points, the interesting one for me being:

public Func<Markdown, string, string> FormatCodeBlock;

If you set this property, when a code block is encountered, your code will be called instead of the default. To make sure I wasn't losing any functionality, I checked the source code of MarkdownDeep to see exactly what it did with a code block:

b.Append("<pre><code>");
foreach (var line in children)
{
    m.HtmlEncodeAndConvertTabsToSpaces(b, line.buf, line.contentStart, line.contentLen);
    b.Append("\n");
}
b.Append("</code></pre>\n\n");

This seemed simple enough, and actually, the code path when you had a custom method was almost the same, it just didn't put the pre/code blocks in:

var sb = new StringBuilder();
foreach (var line in children)
{
    m.HtmlEncodeAndConvertTabsToSpaces(sb, line.buf, line.contentStart, line.contentLen);
    sb.Append("\n");
}
b.Append(m.FormatCodeBlock(m, sb.ToString()));

This meant the only thing I needed to do was surround the string with the pre/code tags. Adding class="prettyprint" was rather trivial:

/// <summary>
/// Overrides the Markdown formatting for code blocks to inject "prettyprint" classes for syntax highlighting.
/// </summary>
private static string FormatCodeBlock(Markdown md, string code)
{
	// Wrap the code in <pre><code> as the default MarkdownDeep.NET implementation does, but add a class of
	// "prettyprint" which is what Google Code Prettify uses to identify code blocks.
	// http://google-code-prettify.googlecode.com/svn/trunk/README.html
	var sb = new StringBuilder();
	sb.Append("<pre class=\"prettyprint\"><code>");
	sb.Append(code);
	sb.Append("</code></pre>\n\n");
	return sb.ToString();
}

Then in my partial class, I simply assigned this method to the FormatCodeBlock property of the Markdown transformer in a static constructor (since this is a partial class, it has direct access to the "markdownTransform" object):

/// <summary>
/// Static constructor to set MarkdownHelper options.
/// </summary>
static MarkdownHelper()
{
    // Override code formatting to support syntax highlighting.
    markdownTransformer.FormatCodeBlock = FormatCodeBlock;
}

With those changes, all my code blocks have the correct class and highlight correctly :-) You can see a sample of a code block on the homepage of the development site where I'm building the blog. You can also see the full source code on Bitbucket (MarkdownHelper.CodeFormatting.cs).

07

May 2011

Setting up NuGet to Automatically Fetch Packages When Deploying to AppHarbor Without Storing Binaries in Source Control

Over the last few days I've been blogging and tweeting about using NuGet without committing the packages folder to source control. David Ebbo blogged about using a pre-build event to fetch packages at build time.

Unfortunately, this doesn't work on AppHarbor because build events are not supported. If you try, you'll find the pre-build step doesn't fire and the build fails due to the missing dependencies :(

I voted on (and tweeted about, lots) a feature request about supporting NuGet natively on AppHarbor. The request has had quite a few votes, and Friism said they'll probably implement it, but in the meantime, this meant I couldn't deploy to AppHarbor. I didn't want to add my packages folder to source control, because even once I remove it when AppHarbor supports NuGet natively, it'll still be in the history (and therefore every clone), which I'd like to avoid.

I scratched my head a little, and re-read the proposed spec for baking this functionality into NuGet/MSBuild (to be honest, I don't actually understand what there is to improve!). The mentions of MSBuild got me thinking - custom build targets!

I opened up my csproj file in Notepad, and scanned through for the "BeforeBuild" step that's included by default but commented out. I removed the comment, and moved my pre-build event into the target:

<Target Name="BeforeBuild">
<Exec Command="&quot;$(SolutionDir)Tools\NuGet&quot; install &quot;$(ProjectDir)packages.config&quot; -o &quot;$(SolutionDir)packages&quot;" />
</Target>

First I checked whether this worked locally, by deleting my packages folder and running MSBuild from the command line. Success! I added in MarkdownHelper and added some test code to a view:

@Html.Markdown("We can use **Markdown!**")

Everything worked fine locally. An "hg ci" and "hg push" later, Bitbucket notified AppHarbor, AppHarbor checked out, built, and successfully deployed!

To show it working, you can see the test page at dev.dantup.com that will form the basis of the ASP.NET MVC / Razor version of this blog, and view the source code that AppHarbor is pulling to see there's no packages folder!

So, it turned out to be quite simple to get it working. I've also notified David Ebbo to see if he'd update his post with this info for anyone reading there that's using AppHarbor! :-)

04

May 2011

Vote for Native NuGet Support on AppHarbor to save your Repositories from The Bloatmonster

I was hoping to post tonight about how awesome BitBucket, AppHarbor and NuGet all worked together. Sadly, I hit a problem with getting NuGet to fetch packages on AppHarbor. First, some background...

Binaries in distributed version control systems are evil.

The problem with binaries in DVCS is that every clone pulls an entire copy of the repository (this is good, normally). If you have ten different revisions of a 10mb binary file, then your clone will include all of these copies - 100mb in total.

David Ebbo posted about using NuGet without committing packages to source control. The idea is that when you check out, you can use NuGet.exe to fetch all the packages based on your packages.config file. This means you can keep your repository lean, but still get all the required dependencies with little effort. In fact, David suggests a pre-build event that will run NuGet automatically! Unfortunately...

AppHarbor does not support build events

This means the pre-build event that executes NuGet to fetch the packages on a clean checkout, doesn't run, and the AppHarbor build will fail due to missing dependencies.

The Fix?

The fix is for AppHarbor to either support build events (tricky, for security reasons), or support NuGet natively, and allow us to tell AppHarbor to automatically execute NuGet to fetch our packages after checking the code out, but before running MSBuild.

So, what are you waiting for? Go and vote for NuGet support on AppHarbor so you can host your ASP.NET MVC applications there (for free, if not very big!) without needing to bloat your repositories with 400MB of NHibernate ;)