this is the slides from the talk i gave at DevGeekWeek2014
further details are in my blog: http://blogs.microsoft.co.il/iblogger/2014/06/25/devgeekweek-2014-slides-and-demos/
2. About Me
• Software architect, consultant and instructor
• Software Engineering Lecturer @ Ruppin Academic Center
• Technology addict
• .NET and Native Windows Programming
@tamir_dresher
tamirdr@codevalue.net
http://www.TamirDresher.com.
5. What are Cloud Patterns
• Architectural Patterns:
“A design pattern in architecture and
computer science is a formal way of
documenting a solution to a design problem
in a particular field of expertise”
(http://en.wikipedia.org/wiki/Architectural_patterns)
7. DevGeek Coffee Shop
• DevGeek Coffee is a well known and
established coffee shop
• In business for 20 years
• Lately, with the increasing competition,
sales are dropping
• Lets Help!
10. What does this has to do with software?
• Cashier == Server
• Basically, this is a scalability issue
• Running in the cloud (potentially) makes
scaling problem appear faster
11. Scale Up
• Add More Resources to a Node
• Faster cashier
– Better CPU to the server
– More Memory
• Faster Coffee machine
– Use a better algorithm/service
12. Everything has a limit
MoneyMoney
CPUCPU
MEMMEMBANDWIDTH
BANDWIDTH
StorageStorage
13. Scale out
• Add More Nodes
– More Cashiers
• Load Distribution
– Round Robin
– Performance
– Other (location, expertise, etc)
16. DevGeek Coffee Shop – The clients complaints
• Long standing
• Sometimes orders gets lost
• Sometimes the line is so long that the
workers close the doors
17. DevGeek Coffee Shop – Latency and throughput
• Latency is a time interval between the
stimulation and response
– Time between ordering and receiving the coffee
• Throughput is the number of requests that
can be served per unit time
23. Azure Queuing Options
• Azure Storage Queues
– Simple, Reliable, Persistent Queue
– Max 200TB and 7 days TTL per message
• Azure Service Bus
– Broader capabilities: publish/subscribe,
remoting, integration patterns
– Max 80GB and unlimited TTL per message
http://msdn.microsoft.com/en-us/library/hh767287.aspx
30. Service Bus Messaging – Dead letters
• the name of the sub-queue is [queueName]/
$DeadLetterQueue
• The path can be obtained using the
FormatDeadLetterPath method of the
QueueClient
• Can be consumed by any other consumer
and check the messages, log them etc.
31. Priority Queue
• The queue may hold message with different
priorities (3-High, 1-Low)
Web Sites
worker role
:
:
worker roleweb role
:
35. DevGeek Coffee Shop – The clients complaints
1. Sometimes the soy milk ran out
2. the barista calls to the storeroom
3. The line is busy
4. The barista move to next order
5. Customer receive an order cancellation
36. Transient Faults
• “Transient fault is a fault that is no longer
present if power is disconnected for a short
time and then restored.” (http
://en.wikipedia.org/wiki/Transient_fault#Transient_fault)
• Many faults in connectivity to cloud are
transient by nature
• Commonly occur when connecting to
service or database
37. Retry Pattern
• If at first you don’t succeed, try try again
(William Edward Hickson)
• Retry Logic
– Linear – every fixed amount of time
– Exponential – if the server is heavy-used
(throttling) we don’t want to flood it
immediate….1 sec….5 seconds….etc.
– Other
38. Operation With Basic Retry
int currentRetry = 0;
while (currentRetry < MaxRetries)
{
try
{
// Calling external service.
await TransientOperationAsync();
}
catch (Exception ex)
{
currentRetry++;
// Check if the exception thrown was a transient exception
if (!IsTransient(ex))
{
// If this is not a transient error
// or we should not retry re-throw the exception.
throw;
}
}
await Task.Delay(TimeBetweenRetries);
}
39. Retry Pattern – Solutions
• Azure Storage IRetryPolicy
• Azure Service Bus RetryPolicy
IRetryPolicy noRetryPolicy = new NoRetry();
BlobRequestOptions requestOptions = new
BlobRequestOptions()
{
RetryPolicy = noRetryPolicy,
};
MessagingFactory factory = MessagingFactory.Create();
factory.RetryPolicy = RetryExponential.Default;
factory.RetryPolicy = RetryPolicy.NoRetry;
40. The Transient Fault Handling Application Block
var retryPolicy =
new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
retryPolicy.Retrying += (sender, args) => {
Trace.WriteLine(args.LastException, "Information");
};
try {
retryPolicy.ExecuteAction(() =>
{
TranisentErrorOperation();
});
}
catch (Exception) {
// All the retries failed.
}
http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx
42. Retry Logic – Not Always Not all The time
• Baristas keeps retrying/failing – Time
Consuming
• Maybe we can call someone else?
• The remote service still might get flooded
• If a failure is not transient, we wish that next
attempts fail immediately
43. Circuit Breaker
• Circuit Breaker pattern prevent repeatedly
trying to execute an operation that is likely
to fail
• continue without waiting for the fault to be
rectified
• Prevents wasting valuable resources
because of the wait
44. Circuit Breaker
• The Circuit Breaker is a proxy
• Monitor the number of recent failures
• Decide if to proceed or do something else
– Throw exception
– Try different destination
45. Circuit Breaker States
Closed Open
Success
Fail [threshold reached]
Half
Open
Retry Timeout
Fail
Success
Fail [under threshold]