Ask a questionAsk a question
 

AnswerHow to Run/Suspend only one role?

  • Saturday, November 07, 2009 12:09 PMAnton Staykov Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Let's say I have more than roles in my CloudService project. When I deploy I want to run only one of them. Or if I run all I would like to suspend one of them at some time.
    Is it possible? Is it something that is in your BackLog?
    Or I have to change the CloudService deployment package to include only roles that I want to run. But then I cannot "Upgrade" because if roles are different a full deployment must be done.

Answers

  • Saturday, November 07, 2009 1:07 PMbwc; Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Anton,

    You're aware that you'll end up paying for each deployed role (multiplied by instance count)? This sounds like an expensive way to set up your business. 

    There has been talk about setting the instance count to zero, but that is currently not supported. If you could set the instance count to zero, this would probably solve your scenario. 

    However to get this to work right now, you'll probably have to look into doing deployments programmatically using the API rather than the web portal. Have you considered this?

    Ta
    BWC;
    • Marked As Answer byAnton Staykov Saturday, November 07, 2009 1:53 PM
    •  
  • Saturday, November 07, 2009 2:16 PMbwc; Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I use a Worker Role to complete multiple tasks. To do this, I spawn worker threads in the Start method. Each of these is inside an If statement, that checks a setting in TableStorage. Setting all of these settings to False, prevents each thread from spawning, and so my Worker Role is "inactive", even though it is deployed and running.

    Similarly in my Web Role, in Application_BeginRequest I have a setting check (Cached this time for efficiency) and if I want to deactivate the website or state "down for maintenance" I can either do Response.Redirect("myHoldingPage.html") or write out a message and do Response.End() This causes a few ThreadAbortExceptions (intentionally) but to the end user the result is that the Website appears suspended, even though again it is deployed and running.

    I think these techniques could help you too.

    BWC;
    • Marked As Answer byAnton Staykov Saturday, November 07, 2009 2:22 PM
    •  

All Replies

  • Saturday, November 07, 2009 1:07 PMbwc; Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Anton,

    You're aware that you'll end up paying for each deployed role (multiplied by instance count)? This sounds like an expensive way to set up your business. 

    There has been talk about setting the instance count to zero, but that is currently not supported. If you could set the instance count to zero, this would probably solve your scenario. 

    However to get this to work right now, you'll probably have to look into doing deployments programmatically using the API rather than the web portal. Have you considered this?

    Ta
    BWC;
    • Marked As Answer byAnton Staykov Saturday, November 07, 2009 1:53 PM
    •  
  • Saturday, November 07, 2009 1:54 PMAnton Staykov Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks BWC,
    However I don't want the instances granularity. Just wanted to suspend a worker role for example. And it is not actually a sceniro, but playing around and testing how things work.
  • Saturday, November 07, 2009 2:16 PMbwc; Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I use a Worker Role to complete multiple tasks. To do this, I spawn worker threads in the Start method. Each of these is inside an If statement, that checks a setting in TableStorage. Setting all of these settings to False, prevents each thread from spawning, and so my Worker Role is "inactive", even though it is deployed and running.

    Similarly in my Web Role, in Application_BeginRequest I have a setting check (Cached this time for efficiency) and if I want to deactivate the website or state "down for maintenance" I can either do Response.Redirect("myHoldingPage.html") or write out a message and do Response.End() This causes a few ThreadAbortExceptions (intentionally) but to the end user the result is that the Website appears suspended, even though again it is deployed and running.

    I think these techniques could help you too.

    BWC;
    • Marked As Answer byAnton Staykov Saturday, November 07, 2009 2:22 PM
    •  
  • Saturday, November 07, 2009 2:23 PMAnton Staykov Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Well,
    This looks good for me! Thanks for that detailed explanation!
    In addition I would add some timer so that on every tick of itI can recheck settings in that table to either stop ot start a thread in worker role. Because what you explained just seems like deployment-time only check.
    Or we can recheck setting on the GetHealthStatus call.
  • Saturday, November 07, 2009 6:13 PMdn2009 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Similarly in my Web Role, in Application_BeginRequest I have a setting check (Cached this time for efficiency) and if I want to deactivate the website or state "down for maintenance" I can either do Response.Redirect("myHoldingPage.html") or write out a message and do Response.End() This causes a few ThreadAbortExceptions (intentionally) but to the end user the result is that the Website appears suspended, even though again it is deployed and running.

    This sounds like a good idea to me.  Thanks for sharing it with us.

    How exactly do you cache the setting?
  • Saturday, November 07, 2009 9:52 PMbwc; Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    There are a tonne of options, but I chose using System.Web.Caching.Cache (through HttpContext.Current.Cache) and then wired up a Custom Cache Dependency that effectively polls the TableStorage, checking whehter the settings have changed.

    BWC;