• Save
Web api scalability and performance
Upcoming SlideShare
Loading in...5
×
 

Web api scalability and performance

on

  • 4,696 views

ASP.NET Web API : Performance and Scalability Key concepts.

ASP.NET Web API : Performance and Scalability Key concepts.

Statistics

Views

Total Views
4,696
Views on SlideShare
4,658
Embed Views
38

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 38

https://twitter.com 38

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Etag demo
  • Cache Control
  • Paging and Throttling
  • Protocol Technique
  • Push Content Stream
  • This test is for (r145; 1,000,000 iterations)
  • Http Batching
  • Push Content Sample
  • Start with blocking sampleStep 1 shows use of task.createnew – explain the concept of blocking threadpool threadStep 2 shows use of async keyword
  • //convert this slide to animation to explain the concept of threadsstatic void SyncMain(string[] args) { ...while (true) { varclient = socket.AcceptTcpClient(); ...vart1 = new Thread(new ThreadStart(() => ...ServiceClient(client);In the main loop we accept new clients (AcceptTcpClient), and for each one we start a new thread (ThreadStart) that calls ServiceClient(), which is this little function that is a lot like the pseudocode I mentioned earlier:static void ServiceClient(TcpClientclient) { using (varstream = client.GetStream()) { stream.Write(quote, 0, 1); // write header while (true) { WriteStockQuote(stream); } } }
  • http://www.iis.net/learn/get-started/introduction-to-iis/introduction-to-iis-architecture
  • DefaultConnectionLimitHKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\MaxConcurrentRequestsPerCPU)ServicePointManager.DefaultConnectionLimit.Few ways you can do this.Best way is to do in global.asax.// See http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx /* 5.If your ASP.NET application is using web services (WFC or ASMX) or System.Net to communicate * with a backend over HTTP you may need to increase connectionManagement/maxconnection. * For ASP.NET applications, this is limited to 12 * #CPUs by the autoConfig feature. * This means that on a quad-proc, you can have at most 12 * 4 = 48 concurrent * connections to an IP end point. Because this is tied to autoConfig, the easiest way * to increase maxconnection in an ASP.NET application is to * set System.Net.ServicePointManager.DefaultConnectionLimitprogramatically, * from Application_Start, for example. Set the value to the number of concurrent * System.Net connections you expect your application to use. I've set this to Int32.MaxValue * and not had any side effects, so you might try that--this is actually the default used * in the native HTTP stack, WinHTTP. If you're not able to set * System.Net.ServicePointManager.DefaultConnectionLimit programmatically, you'll * need to disable autoConfig , but that means you also need to set maxWorkerThreads and maxIoThreads. * You won't need to set minFreeThreads or minLocalRequestFreeThreads if you're not using classic/ISAPI mode. * */System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue;MaxConcurrentRequestsPerCPUYou can insert maxConcurrentRequestsPerCPU in aspnet.config like following Of you can do following in registryHKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\MaxConcurrentRequestsPerCPU = 5000It's not clear if you have v3.5 SP1, which is required in order to set the value in aspnet.config, so please try the registry change and restart IIS.autoConfigSpecifies whether to automatically configure the following settings to achieve optimal performance based on the machine configuration:The maxWorkerThreads attribute.The maxIoThreads attribute.The minFreeThreads attribute of the httpRuntime element.The minLocalRequestFreeThreads attribute of the httpRuntime element.The maxConnection attribute of the  Element (Network Settings) element.The values are set according to the KB article at http://support.microsoft.com/?id=821268.This attribute does not affect the .NET Framework client applications; only ASP.NET applications.The autoConfig attribute can be one of the following values.TermDefinitionTrueIndicates that ASP.NET automatically configures the attributes in the preceding list to achieve optimal performance based on the machine configuration.FalseIndicates that ASP.NET should use the explicitly defined values for the attributes in the preceding list.The default in the Machine.config file is True, unless there is a previously existing configuration.

Web api scalability and performance Web api scalability and performance Presentation Transcript

  • Discover. Master. Influence.
  • Lead Consultant at Readify @H_Desai http://himanshudesai.wordpress.com 2Discover. Master. Influence.
  • With thanks to our sponsors
  • • Request life cycle • Server Load Reduction • Measuring Performance • Server Configuration • Tools Discover. Master. Influence.
  • • Response time or latency – Measured @Server/Measured @Client • Throughput – Requests/sec • Resource utilization – CPU/Memory/Disk IO/Network IO Discover. Master. Influence.
  • HTTP request/response handling Client Server
  • 7Discover. Master. Influence. • Http Dispatcher Formatting Exception filters Your Code Request Action Filters Model Bind Authorization Filters Select action Route to controller Response
  • • Transferring Less Data – Http Caching (Etag,Max Age,Expires) –Efficient Content Types –Batching –Push Content Stream(Chunked) Discover. Master. Influence.
  • 9Discover. Master. Influence. Technique # 1 (Etag)
  • 10Discover. Master. Influence. Technique # 2 (Cache Control)
  • 11Discover. Master. Influence. Technique 3 (Throttling)
  • 12Discover. Master. Influence. Technique 4 (protocol)
  • Discover. Master. Influence. 0 500 1000 1500 2000 2500 3000 3500 4000 4500 xml json bson protobuf Formatters Payload (lower value - better)
  • 15Discover. Master. Influence. Serializer size serialize deserialize protobuf-net 3 268 1,881 proto# 3 76 1,792 BinaryFormatter 153 6,694 8,420 SoapFormatter 687 28,609 55,125 XmlSerializer 153 14,594 19,819 DataContractSerial izer 205 3,263 10,516 DataContractJsonS erializer 26 2,854 15,621 Source: https://code.google.com/p/protobuf-net/wiki/Performance
  • Discover. Master. Influence. How to implement Resource?
  • • I/O bound operation • Dashboard type app with low users • Long polling Discover. Master. Influence.
  • 20Discover. Master. Influence. Asynchronous (Demo)
  • Discover. Master. Influence. Measure?
  • • ASP.NET • CLR Performance Counters Discover. Master. Influence.
  • 24Discover. Master. Influence. • ASP.NET Performance Counters (IIS 6.0 or II7.0 classic mode) Client IIS App Domain App Domain QueueNamed Pipe Requests waiting to be written to client WebServiceISAPI Extension ReqSec ASP.NET Rejected Requests ASP.NET Requests Wait Time ASP.NET Requests Queued ASP.NET Requests in Application Queue ASP.NET Application Requests Executing ASP.NET Worker Process Restarts ASP.NET ApplicationsRequest Sec Pipeline ASP.NET Worker Process
  • 25Discover. Master. Influence. • Additional Performance Counters (IIS 7.0/7.5 integrated mode) Client IIS Named Pipe Pipeline W3SVC_W3WP Process W3SVC_W3WP(_Total)Requests / Sec W3SVC_W3WP(_Total)Active Requests
  • Discover. Master. Influence.
  • • IIS App pool – Queue Length (1000 by default) – Idle timeout (default is 20) • Aspnet_config or (registry) – maxConcurrentRequestsPerCPU – in v4.0 is 5000 (default) • ServicePointManager.DefaultConnectionLimit • Max ADO.NET connection Pool Size (default is 100) • Machine.config – Processmodel.Autoconfig (turned on by default) 28Discover. Master. Influence.
  • • Performance counters • Visual Studio Load test • Visual studio profiler (CPU/Memory/Concurrency measurements) • 3rd Party tools like Red gate’s ANTS profiler • Apache Benchmark 29Discover. Master. Influence.
  • • Transfer less data and make use of caching • Use efficient mime types for internal application • Don’t block your thread pool threads • Measure your throughput by tests • Tweak IIS settings when needed • Don’t run your test on Client OS 30Discover. Master. Influence.
  • Discover. Master. Influence.