问题
I want to make a Windows Azure application as fault-resistant as possible and I need to be able to make roles crash intentionally to test how the whole application recovers from such crashes.
I guess I could insert code right into role that would obtain a random number and decide to crash with some rather low probability. The real problem is
if( isTimeToCrash() ) {
//what exactly do I do here?
}
how to crash a role once I decide it is time.
How do I reliably crash an Azure role intentionally?
回答1:
You can either RDP into the machine or use a Startup task to add a scheduled task that will periodically kill the 'WaAppAgent' process. Powershell is pretty good here to find and kill the process. You need to be an admin to do it. This will sever the communication with the fabric controller for a period of time until it recovers and restarts the process. IIRC, it will also kill your RoleEntryPoint code (running under either WaWebHost or WaWorkerHost). That will simulate a pretty big failure.
If you want to get really fancy, run a background startup task that listens to a queue and will kill the process on demand when it sees a queue message. Note, you would not put this code in RoleEntryPoint, it would need to be a startup task running as 'background' or you would also kill the process that is crashing your role.
回答2:
I am not sure about crashing a role, but using Role Management API you can reboot a role. You can look at this sample
回答3:
For a worker role, you can throw an exception from your Run() and let it go unhandled. However, I don't know if that meets your qualification as a "crash" - the role would be gracefully recycled.
we roles tend to catch unhandled exceptions via IIS, so dunnry's suggestion probably gets you much closer to the ASOD (Azure Screen of Death) that you're looking for.
来源:https://stackoverflow.com/questions/6095580/how-do-i-intentionally-make-azure-role-crash