Greetings. I’m Jeff Johnson and I founded Digital Ruby in 2009 in order to learn how to run a software company, teach myself mobile programming and expand my skills and knowledge. I craft iOS apps, websites and server software.
My latest blog post:
Aug 5, 2014
Recently I coded up a very naive message handler in C# that read in received messages from a certain service in an ASP.NET MVC controller method and then inserted each message into a SQL Server table for processing. When hundreds of calls flooded my system per second, it quickly fell to it’s knees.
Inserting one object at a time to SQL server required a separate network call to the SQL Server database, and did not take advantage of any bulk insert capabilities in SQL Server. I quickly realized that I needed to do something fast as this was a production system. I decided that I would batch up all of the messages every few seconds and then bulk insert them into SQL Server.
Since all web services can have many concurrent connections, I needed a data structure that could add and remove items in a thread safe way. The Microsoft .NET developers have done a great job with
System.Concurrent.Collections.BlockingCollection is a great way to represent a thread safe queue. You can add items to the back and take them to the front.
In my new implementation, when I get a call to my controller method, I simply insert a message into a static instance of a BlockingCollection and that is all. I then have a timer that fires every few seconds, gets the count of the blocking collection, takes that many items off and then bulk inserts the messages into SQL Server. This new implementation is orders of magnitude faster than the one at a time implementation.
In short, if you have any system that handles messages and puts them into any kind of database, be sure to do batching. Even a batching interval of 1 second will give you vast improvements in performance.
- The Power of Batching
- Google Penalty – Why removing links probably won’t help you
- Get a CDN (Content Delivery Network) Immediately
- Wimshire – Diablo 3 Reaper of Souls
- iOS StoreKit Receipt Verification and Validation
- All Code is an API – One Insight on How to Design Good Interfaces in Programming
- Quick and dirty profiling for iOS
- Why You May Not Need a Schedule
- To the Cliffs – What Happens After the First Week for a New iOS App
- TexturePacker – A Fast and Easy Utility to Create Spritesheets
- The Cheapest Best Dedicated Server
- The Price is Right
- iAd vs AdMob
- Birdshot is now on the iOS App Store!
- Manual Penalty or Bad Search Algorithm?
- Bird Flight is now on the iOS App Store
- You Doodle – Now With Fleksy Integration
- No Silver Bullet
- Sage Advice from Quark
- Flappy Bird, Super Ball Juggling and Shuriken Block – Oh My
- New You Doodle Icon
- Solving the iOS App Store Search Problem
- Does Your App Icon REALLY Matter That Much?
- Factorials, Meetings and a Visual
- iOS Hardware and Model Version Numbers