Git Product home page Git Product logo

performance-optimization's Introduction

Optimizing Performance for Cloud Applications

This repo contains sample code for a set of performance antipatterns.

Documentation and guidance for these patterns can be found on the Azure Architecture Center. For each antipattern, the documentation describes why the antipattern typically occurs, symptoms of the antipattern, and techniques for resolving the problem. The corresponding sample code shows (1) the problem and (2) a recommended way to fix the problem.

Antipattern Description Load test
Busy Database Offloading too much processing to a data store. Load testing Busy Database
Busy Front End Moving resource-intensive tasks onto background threads. Load testing Busy Front End
Chatty I/O Continually sending many small network requests. Load testing Chatty I/O
Extraneous Fetching Retrieving more data than is needed, resulting in unnecessary I/O. Load testing Extraneous Fetching
Improper Instantiation Repeatedly creating and destroying objects that are designed to be shared and reused. Load testing Improper Instantiation
Monolithic Persistence Using the same data store for data with very different usage patterns. Load testing Monolithic Persistence
No Caching Failing to cache data. Load testing No Caching
Synchronous I/O Blocking the calling thread while I/O completes. Load testing Synchronous I/O

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

performance-optimization's People

Contributors

atoakley avatar bennage avatar ckittel avatar dragon119 avatar dyasik avatar ferantivero avatar francischeung avatar gitter-badger avatar hanzzhang avatar hveiras avatar johnpwsharp avatar mattjohnsonpint avatar mekod4 avatar rohitsharma-pnp avatar snobu avatar trentmswanson avatar wilka avatar woodp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

performance-optimization's Issues

HttpClient usage: MSDN vs the ImproperInstantiation article

The ImproperInstantiation article makes a recommendation to reuse a single HttpClient instance for handling multiple requests.

The article even has this note:

Note: The key element of this anti-pattern is that an application repeatedly creates and destroys instances of a shareable object. If a class is not shareable (if it is not thread-safe), then this anti-pattern does not apply.

But the documentation of HttpClient says:

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Is this an error in the HttpClient docs, or is the ImproperInstantiation article wrong?

add note to readme regarding the version of AdventureWorks

The new Azure portal makes it easy to provision an AdventureWorks db, however it uses a newer schema that differs from what we've been testing with.
We will continue to use the old schema (since it doesn't affect the perf tests), but we should be very clear about this in the README.

Suggestion for alternative / functional option

These single instances are very broadly useful objects that people will want to be able to use in very simple contexts. Azure function promotes and encourages smaller/simpler functions for simple use cases. In such contexts, the "try with resources + a lambda" style can give developers access to the instance and the freedom to use it however they want at the callsite, without having to wrap all their various HTTP requests in separate class methods, and go deep into abstractions with lots of boilerplate.

Again, it's an alternative style that makes it easier to use HttpClient in a healthy way for simple functions.

Here's an example for HttpClient

  public class SingleHttpClient
   {
       private static readonly HttpClient HttpClient;

       static SingleHttpClient()
       {
           HttpClient = new HttpClient();
       }

       public void DoWithClient<T>(Action<HttpClient> action)
       {
           action(HttpClient);
       }

       public async Task DoWithClient(Action<HttpClient> action)
       {
           await Task.Run(() => action(HttpClient));
       }

       public T DoWithClient<T>(Func<HttpClient, T> func)
       {
           return func(HttpClient);
       }

       public async Task<T> DoWithClient<T>(Func<HttpClient, Task<T>> func)
       {
           return await func(HttpClient);
       }
   }

And then to use., something like this...

        HttpResponseMessage response = await new SingleHttpClient()
                .DoWithClient(async (client) => await client.GetAsync("http://somehost:8080/api/"));

And, because this is a composeable style, you could write a DocumentClient using the same strategy, which calls upon this SingleHttpClient class just like the user would.

Just a thought, thanks for the great content here.

'provisioning' folder and anti-pattern template

We should remove 'provisioning' folder and move script file to root if it's useful. Is it still valid?
We should also modify the anti-pattern template. It doesn't refrect the actual structure.

Chatty IO Completion

The Chatty IO sample needs to be completed with the following:

  • Add and configure Azure cloud configuration project
  • Connect to SQL Azure database instead of local database

Include docs in solution

All solutions should have a "Solution Items" folder containing the markdown documentation for the pattern and the LICENSE file.

add test "recipes" for each antipatterns

We need to describe how we went about testing each antipattern.

  • What did our deloyment look like?
  • How were the load tests configured?
  • What were our reasons for choosing these settings?

File Headers and License file

Every C# file should have a copyright header as follows:

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

We also then need a LICENCE file. :)

Improper Instantiation Question

Really great stuff here but being able to determine when a class\methods is shareable seems to be 'conflicting'. Example of the HttpClient, talked about in the docs/ImproperInstantiation.md doc. If I go look at the docs for it states the following

'Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.'

The HttpClient.GetStringAsync is not marked as 'public static' so it appears to not be thread safe to me. Am I missing something here?

Maybe recommend a Queue

Let me just start by saying that i admire the work you guys put into these performance optimization documents and that the level of detail and attention is probably unprecedented.

If i may, i'd like to bring this to your attention:
In the Chatty IO document here https://github.com/mspnp/performance-optimization/blob/master/ChattyIO/docs/ChattyIO.md, after recommending buffering data into memory

You should consider the following points:

  • [...]
  • [...]
  • Data buffered in memory to optimize write requests is vulnerable if the application crashes and may be lost.

the reader might feel that he or she just traded performance for risk and is probably a bit dissapointed. Which is a fair trade in most situations. But, am i completely wrong in saying this is one scenario in which a Queue would make sense, thus alleviating much of the risk of data loss given its durable nature?

Worker Role != Webjob

In this document
https://github.com/mspnp/performance-optimization/blob/master/BusyFrontEnd/docs/BusyFrontEnd.md

Using a worker role is simply one solution. If you are using Azure Websites, you can use other options such as WebJobs.

Webjobs are running inside the same instance as the Azure Website, so it's not going to have a decoupling effect. That's what's i've seen in production. Sure you may scale out to let's say 10 instances (so, 10 x Webjobs) but i feel like this has the same effect as just doing 10 x WebRole.

(The Hanselman):
http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx

WebJobs aims to make developing, running, and scaling this easier. They are built into Azure Websites and run in the same VM as your Web Sites.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.