CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

April 2006 - Posts

  • My Locals Guide to Boston's TechEd Week 2006

    You could fill your entire week at the conference, going to the scheduled MSFT events and parties, eating lots of chips, stuffing your backpack with free Schwag, and riding escalators endlessly.  There’s never a shortage of things to do at TechEd.  Personally, I can only stand so much pre-arranged fun so I usually take conferences as an opportunity to explore the city it’s hosted in.  If you’re like me, you will want to venture out on your own and experience the underbelly of Boston during your TechEd week. 

    Well, I spent a good number of my formative years freezing my ass off in Boston and I spent much of my time there going to shows and seeking out the best food in the area.  I’ve come up with a very short list of the best Boston has to offer that week. – So if you get sick of banquet food and aren’t into this year’s party band, here’s a handful of things to eat and do in this great city – my local’s guide to Boston’s underbelly for the week of June 11th.

    Food

    Rami’s

    Rami makes perhaps the best Falafel I’ve ever tasted.  The Schwarma is incredible too.  Can’t go wrong if you’re into middle-eastern food.  By T - take the green “C” line to Coolidge Corner, and walk two blocks up Harvard st.

    Boca Grande

    I literally ate lunch here every day for a year.  Best tacos around, and they also have a great “Al Pastor” taco that will make you feel like you’re in Ensenada. By T - take the green “C” line to Coolidge Corner Boca Grande is across from the Trader Joe's.

    Matt Murphy’s

    Forget all that Irish Crap in downtown Boston, and definitely skip the fake “Cheers” bar near the Commons.  If a beer drinker you are, head straight to Matt Murphy’s in Brookline and order a Murphy’s (pronounced MAIR-FEES).  Their food is great too, and you may catch a traditional Irish Sessiun band in the corner. To get there take a cab.

    Mary Chung

    Probably the only restaurant menu hosted at MIT, and that should tell you something.   Heck Dave Winer even has pictures on Scripting News of the food!  This place should be required eating for any software professional visiting Boston.  Packed with hackers from MIT, this is undoubtedly the best Chinese food in the area and probably the entire east coast, NYC’s Chinatown included.  You’d be crazy not to eat there at least once during your trip.  Order the Dun Dun Noodles, and the Pan Fried Peking Ravioli.  By T - take the "Red" line to Centeral Square.

    Music

    Arctic Monkeys / We Are Scientists – This could be the best show of the year, and it’s happening the week of TechEd!   Thursday, June 15th. Get your tickets before they sell out. 

    If you can’t go see them, the Eels may do nicely too, they’re playing the same night at the Somerville (Pronounced SUM-AH-VUL-DUDE) theatre.

    Have Fun!

    -Brendan

  • The "Cats In Sinks" Phenomenon

    Sometimes an irrelevant site gets listed at the top of a Google search, due not to the page's relevance, but because Google's page rank algorithm bases it's page relevance partly on inbound links. Take for example a simple Google search for "sinks."  The number 1 result?  Cats in Sinks.  A funny site, but it's completely irrelevant to the topic of sinks in general.  Why is it listed first?  Because everyone on the planet with a cat and a blog has linked to them.  As of this post, I’m one of these people.

    It's not a good thing.

    You ever wonder how blog spam works? Spammer's attacking blogs don't ever hope you'll actually click on a link for cheap Ambien or Viagra, when they post a spam comment. It's actually referred to as spamdexing. They're hoping that Google will be fooled into giving their site a higher page rank, because your site (which already has a good page rank) is linking to them. 

    Hopefully someday, this will be a thing of the past.  Those rocket scientists over at Google will no doubt figure it out.  Until that day, I thought it needed a name.  I'm hereby declaring it the "Cats in Sinks" Phenomenon.

    -Brendan

    Technorati Tags: , , ,
  • Donations for Baby Drew

    As you may know, one of our bloggers, Raymond Lewallen's son Drew recently passed away.  You can find out more about Drew's story here.

    The Lewallens Need our Help

    They have set up a fund in Drew's name through Oklahoma University Children's Hospital Volunteers. This will allow all donations for Drew to go to a central location and the Lewallen's will have control over where the money is spent within the hospital. Their plan is to direct it to the Level III NICU where Drew spent his time and to Aikman's End Zone, a wonderful place within the hospital for sick children and their families.

    The Drew Lewallen Fund
    Children's Hospital Volunteers
    940 NE 13th
    Oklahoma City, OK 73104

    I also understand that the expenses can be enormous for the family in times like this.  If you'd like to help by donating directly to the Lewallens to help with related expenses, you can do that by paypal, at rlewallen@gmail.com.

    If you can help, please do!  

    Thanks! 

    -All of us at Codebetter.
  • Going Beyond AJAX - What's Really Needed for Asynchronous Web Development

    To me, you can’t get too far into the whole Web2.0/Ajax/Mashup/Whatevr discussion without coming up with a method of handling long running web requests.  AJAX helps us in the area of providing a responsive UI during web requests, but it only gets us so far.  The more we begin to mash together all these remote webservice calls, fetch  xml data to display and perform lots of real work in our web applications, the greater the need to go beyond AJAX and use real-life honest to goodness asynchronous method invocation on the server. 

    What? I thought AJAX was Asynchronous?

    In a sense, AJAX isn’t really asynchronous at all when it comes to HTTP requests.  An AJAX web request is a synchronous web request just like any other.  All AJAX solutions really are doing is using the browser’s built in threading (via JavaScript) to make multiple web requests for you, and then updating the page when the server responds.  These are really client-side hat-tricks, and will only get you so far and requires that the data you’re fetching on the servers is readily available.  What happens when the server doesn’t respond for ten minutes or even more?

    You will run into problems with page requests that bump up against ASP.NET’s ScriptTimeout (which is set at 90 seconds by default).  AJAX or no AJAX, if your web method takes longer than your ScriptTimeout, you’re going to have problems.  You could try to guess the length of time that this will take and set your script timeout to some really large value, but here you’re just guessing what will work, and you run into other problems as well.  This article here nicely describes the general problem you’re faced with with requests timing out.

    Consider the following Code

    protected void Button_Click(object sender, EventArgs e)
    {
           int totalSeconds = 5;
          
    Thread.Sleep(totalSeconds * 1000);
           Label2.Text =
    "Our Long Running Method finished at " + DateTime.Now.ToLongTimeString() + " and took " + totalSeconds + " seconds to complete";

    }

    If you crank your RequestTimeout down by adding this line to the Web.Config file:

    <httpRuntime executionTimeout="1"/>

    … you’ll see this screen, AJAX or no AJAX:

    So How Do I Build Truly Asynchronous Web Applications?

    As far as I can see it, and you should never trust me, but you have two good choices for making applications that can properly handle long running requests:

    1) Use a message queue.  This is often a good choice where you need a guarantee that the process completed. You could use MSMQ or something else to make sure you’ve got the ability to reliably process requests on the server. 

    2) Use Asynchronous Method Delegation on the server, create a polling mechanism  let the user know when the method has finished.  This “Fire and Forget” method of server side processing is a good, simple, straightforward method of doing work on the server. In fact, the most basic method of doing this is so simple, that you can implement this with very little code:

    protected void Button1_Click(object sender, EventArgs e)
    {
            LongRunningMethodAsync();
    }

    private delegate int LongRunningMethodDelegate();

    /// <summary>
    /// The Long running method async call.
    /// </summary>
    private IAsyncResult LongRunningMethodAsync()
    {
       
    LongRunningMethodDelegate longRunningDelegate = new LongRunningMethodDelegate(LongRunningMethod);
       
    IAsyncResult ar = longRunningDelegate.BeginInvoke(new AsyncCallback(LongRunningMethodCallback), null);
       
    return ar;

    /// <summary>
    /// The long running method callback.
    /// </summary>
    private void LongRunningMethodCallback(IAsyncResult ar)
    {
       
    AsyncResult aResult = (AsyncResult)ar;
       
    LongRunningMethodDelegate longRunningDelegate = (LongRunningMethodDelegate)aResult.AsyncDelegate;
       
    int totalSeconds = longRunningDelegate.EndInvoke(ar);
    }

    /// <summary>
    /// The long running method.
    /// </summary>
    private int LongRunningMethod()

       
    Random rand = new Random(Guid.NewGuid().GetHashCode());
        int mseconds = rand.Next(90000, 100000);
        Thread.Sleep(mseconds);    
        return (int) (mseconds / 1000);
    }

    So Do we need AJAX?

    YES!  Ajax is a very important piece of the puzzle, and solves many of the problems faced with creating responsive web User Interfaces.  In fact, the combination of AJAX using something like ATLAS with Asynchronous Method Delegation can really add up to some powerful stuff.  I’ve put together a small sample application that shows how to use ATLAS to create a progress bar that shows the status of the long running method, called using Asynchronous delegation on the server.

    This application uses ATLAS to provide the AJAX user interface, and presents three link buttons that call methods both asynchronously and synchronously on the server with the ScriptTimeout property set really low to simulate long running request problems.   It also uses a cool feature of ATLAS, the TimerControl, to provide the polling code necessary to update the UI and show a progress bar.  Download the code here to try it out for yourself.  I’ve had to rip out the ATLAS script stuff because of the ATLAS eula, but download ATLAS, and copy the Microsoft.Web.Atlas.dll to the bin directory, and the ATLAS Scripts to the ScriptLibary directory and you should be able to experiment with this code.

    Further Reading

    Fritz Onion has a great MSDN article titled Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code and also mentions that the above solution actually uses a thread from the thread pool, so it wont help with issues of scaling an application that has a lot of long running operations. To get around this you’d want to create your own threads, pool and manage them by hand, something I’m not comfortable doing on my own Wink [;)].  But if you need to scale an application AND provide lots of long running processes at once, you’ll want to look there.

    -Brendan

    Technorati Tags: , ,

More Posts