Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3607 Comments | 0 Trackbacks

News

Archives

Post Categories

 

[Source: http://geekswithblogs.net/EltonStoneman]

We’ve had a couple of projects recently with similar requirements to process an Excel file as a batch upload of data. One was a BizTalk project where the FarPoint Spread pipeline component was a good fit; the other was a Web app where we put together a custom parser based on the open-source ExcelDataReader. The custom solution was appropriate for the expected size of upload files, but wouldn’t scale well to deal with large files quickly, so I wanted to look at a distributed alternative using nServiceBus. My sample implementation is on MSDN Code Gallery here: nServiceBus Excel Upload. I’ll look at a comparative BizTalk solution in a future post.

If you haven’t come across nServiceBus, it’s a queue-based messaging framework which is inherently asynchronous. “Scalability and reliability are in its DNA”, and it has some impressive case studies. Using nServiceBus you can set up a simple publish-subscribe architecture between nodes, or a load-balanced architecture with a central distributor. In the distributed version, the upload sample looks like this:

(Note that the diagram represents the bus as a separate entity, in reality it’s distributed among the queues of all the nodes. The diagram also omits the distributor).

In nServiceBus, services are requested by publishing messages onto the bus. Requests are fulfilled by a handler which subscribes to a type of message. The Excel upload sample takes a workbook which contains a set of products and uploads them to the AdventureWorks database. There are three types of message:

  • StartBatchUpload – published when a file has been received and is ready to be processed; subscriber does some basic validation on the Excel data structure, and then for each row in the worksheet publishes an AddProduct message;
  • AddProduct – subscriber maps the product defined in the message to a stored procedure call which inserts the new product. When the last product in the batch is reached, sends a BatchStatusChanged message to the original publisher of the StartBatchUpload message;
  • BatchStatusChanged – logs the status change and renames the Excel upload file.

This is a basic example, more validation would be expected, but the workflow is representative. Parsing the Excel file is done quickly, allowing for any number of nodes to participate in the resource-intensive work of creating the products. Using a single host with 5 threads, an Excel file with 3,500 rows takes just over 4 minutes to process on a dev laptop. That’s 13 messages per second which is nothing special, but this is on a single host which is also running the distributor and SQL Server. The processing host has a flat memory profile (consistently around 40Mb) and runs at less than 20% CPU. The distributor takes around 15% CPU, and MSMQ another 15%.

For a much larger upload – 12,000 rows – the processing and memory profile is the same, and the upload takes around 14 minutes (~14 messages per second) on the same infrastructure.

Running the Sample

Access to a SQL Server instance with the AdventureWorks sample database installed is a pre-requisite. You’ll need to add the new stored procedure with uspInsertProduct.CREATE.sql. The connection string used by the host is specified in ExcelUpload.Host.exe.config (defaults to unnamed local instance).

You’ll need MSMQ running on all nodes. Queues are specified in configuration and are created by nServiceBus if they don’t exist – an exception is the storage queue for the distributor which needs to be manually created, this PowerShell snippet will do it:

      [Reflection.Assembly]::LoadWithPartialName("System.Messaging")

      [System.Messaging.MessageQueue]::Create(".\Private$\distributorStorage", $true)

Unzip the file ExcelUpload.Binaries.zip. You’ll have a batch file – start.cmd – and five subdirectories – Client, Host, Distributor, SampleFiles and Drops. Run start.cmd, check the console screens for errors, then copy one of the Excel files from SampleFiles to Drops. You should see activity in the host, client and distributor console screens, and new rows being added to the [Production].[Product] table.

If you drop the same file twice, the unique key on Products will be violated, so the upload will error. On a fresh install there are under 1000 products, so this resets the table to the default state:

delete [Production].[Product] where ProductID > 999;

Implementation Details

The sample uses the release version of nServiceBus – 1.9 – as the distributor was broken in the 2.0 beta at the time of writing.

The two console apps run the “client” (which monitors a configured file location for an Excel drop, and publishes the StartBatchUpload message), and the “host” (which subscribes to StartBatchUpload and publishes AddProduct and BatchStatusChanged messages). Both use Topshelf so they can run as a console, or can be installed as a Windows service (e.g. ExcelUpload.Client.exe /install).

If you want to run several hosts on the same machine, they will need to use different queues. Copy the whole of the Host directory, and modify ExcelUpload.Host.exe.config to specify a unique queue name:

InputQueue="ExcelUpload.Service.1.InputQueue"

Then run ExcelUpload.Host.exe from all the copied locations, and you’ll see the console hosts sharing the message processing when a file is dropped.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Wednesday, November 18, 2009 9:46 AM

Feedback

# re: Processing an Excel upload with nServiceBus 1/29/2010 5:13 AM Nanny Cams
I was just looking for something like this for one of my upcoming projects. That example that you have made is perfect for what i am planning to do.

# re: Processing an Excel upload with nServiceBus 2/7/2010 2:36 PM Toys
I was having the same problem when doing batch upload in MS Excel. I have looked everywhere for a possible solution, but found none. I'm glad I came across this article. I'm not familiar with nServiceBus Excel Upload and I'll definitely look into it.

# re: Processing an Excel upload with nServiceBus 2/11/2010 4:21 AM Bed and Breakfast Napoli
That's an amazing post. I really appreciate for this.It’s my first visit.I like very much your way of presentation.Thanks for making such a cool post which is very well written.Thanks again.Keep blogging.

# re: Processing an Excel upload with nServiceBus 3/4/2010 3:07 AM david
I am very happy with your post.Really very interesting post.Data Recovery Software|Guard Process

# re: Processing an Excel upload with nServiceBus 3/10/2010 9:47 PM Adam
Hello. I'm new to the whole idea of SOA / messaging etc. and I can see how it lends itself to more loosely coupled, distributed, scalable systems. However, you mention that your custom solution "wouldn’t scale well to deal with large files quickly". However, 12000 records in 14 minutes seems excessively slow to me. Is this quick for using an ESB? Considering yours is a contrived example, should I expect worse performance in reality (although a production environment would be distributed rather than all on a development box)?

In the past, I have done similar tasks using a SQL database as a kind of message bus, but I never would have gotten away with this kind of performance. Although you do say that adding a product is "resource-intensive work", so I may be missing the point here due to the simplified nature of the example! Are we talking about a scenario whereby adding a product takes longer than we would like to have a database transaction open for?

Also, I don't see how this is robust, since if someone pulls the plug halfway through the 14 minutes, wouldn't the batch remains half-imported? I'm probably missing the point though. Thanks.

# re: Processing an Excel upload with nServiceBus 3/24/2010 8:59 PM MuratCan
;)
sohbet

# re: Processing an Excel upload with nServiceBus 3/26/2010 3:34 AM Cake Business
Thanks for this post. I have been trying to learn how to do more things with nServiceBus. I find it very complicated. This helped me a lot.

# re: Processing an Excel upload with nServiceBus 4/10/2010 4:35 PM Chris Pritchard
12,000 messages may be slow, but it's important to know when going for high-volume, scalable services, the time it takes to process is not as important as the fact that that time can remain constant as the demand for the system increases. It is possible to have multiple servers working a queue. Also, if the database goes down, all the messages are still available to run again. If you process a file directly to the database, and it goes down, you have no way to redo anything except delete what data was put in and start over.

I am doing something similar, but the amount of data for a single file is expected to go up as high as 800,000 records. If multiple users are adding files and the total number of records reaches the millions, it's good to know that I have NServiceBus helping me out.

I took a different approach since my files are going to be so large. The first thing I did was to chunk up the file into messages with about 10,000 records of raw data (this number is configurable). Once they are in the queue, I get complete fail over for them. So, I do have a couple extra steps - this is to answer some of the questions people are asking here :)

I also had another service which watches files on the FTP server which notifies the import process to download the file and process it. If you want that service, I'll give it to you. You would have to customize it a bit to work for you, I am sure.

I really like the diagram, it makes a clear picture of the process. I'm pretty lame at those . . .

# re: Processing an Excel upload with nServiceBus 5/12/2010 7:50 AM vacanze isola d'elba
Excellent in all aspects. Sounds interesting. I think I’ll have to check it out and see what it’s all about.



# re: Processing an Excel upload with nServiceBus 5/17/2010 8:23 PM Google First Page
Very excellent post. I am beginning to see how Excel is used in more demanding applications. I am going to check this out in more detail when I have some time.

# re: Processing an Excel upload with nServiceBus 6/1/2010 7:32 AM Serre
Really it's an awesome blog.I agree with most of what you are saying here.Thanks for the share!Waiting for your next upcoming post.

# re: Processing an Excel upload with nServiceBus 6/3/2010 2:18 AM residence Lucca
Pretty cool post. I just stumbled upon your blog and wanted to say that I have really liked reading your blog posts.Thanks a lot for sharing.Keep blogging.

# re: Processing an Excel upload with nServiceBus 6/7/2010 8:25 PM Jubail
awesome blog i agree with the all what you have

Top 10

# re: Processing an Excel upload with nServiceBus 6/9/2010 3:03 PM Financial
I have been trying

# re: Processing an Excel upload with nServiceBus 6/14/2010 3:27 AM Golf Course Advertising46
I am interested very much in the subject matter of your blog.Its really a very enjoyable blog.And i just like it.Thanks a lot.Keep blogging.

# re: Processing an Excel upload with nServiceBus 9/7/2010 5:39 AM online bingo bonus
Unit Testing Silverlight and Windows Phone 7 Applications

Silverlight Performance on Windows Phone

Distributing and Monetizing Windows Phone Applications and Games

Development and Debugging Tools for Building XNA Games for Windows Phone

# re: Processing an Excel upload with nServiceBus 9/25/2010 7:11 AM home automation systems764
The topic which you have discussed is very informative as well as valuable for all.Thanks a lot.I really appreciate it.Hope will post again soon.

# re: Processing an Excel upload with nServiceBus 10/11/2010 2:30 AM wealth magazine investor educati
Interesting post and thanks for sharing. Some things in here I have not thought about before.Thanks a lot.

# <A HREF="http://www.prlog.org/10354498-cell-phone-spy-software-free-mobile-spy-15-only.html">cell phone spy software</A> 10/19/2010 8:06 AM sunaina
Really helping post.I totally work on excel on office beacuse my job is a data entry operator.I want more applications in excel

# re: Processing an Excel upload with nServiceBus 11/9/2010 8:12 AM Stairlifts
A sample implementation of messaging using nServiceBus to process an Excel upload file. Uses distributed pub-sub for scalability, and ExcelDataReader from CodePlex for performance. Based on release 1.9 of nServiceBus.

# re: Processing an Excel upload with nServiceBus 12/6/2010 5:07 AM best coffee maker
This is a very good post.I need to test NServiceBus myself.And I think this is an excellent example for getting started with NServicebus.From my point of view should be contained in the official samples of the NServicebus package!

# re: Processing an Excel upload with nServiceBus 12/15/2010 5:41 AM paris visite
The resource like the one you mentioned here will be very useful to me! I will post a link to this page on my blog.

# re: Processing an Excel upload with nServiceBus 12/16/2010 5:27 AM bmw air conditioning compressor
Have found your web page. My pal mentioned it to me before, yet never got around to checking it out until now. I must express, I'm floored. I really enjoyed reading through your posts and will absolutely be back to get more.


# re: Processing an Excel upload with nServiceBus 1/12/2011 7:29 AM eve online 60 day
This is a really excellent read for me. Must admit that you are one of the coolest blogger I ever saw. Thanks for posting this useful article.


# re: Processing an Excel upload with nServiceBus 1/18/2011 5:34 AM Terrain a Vendre
Spreadsheets created using Microsoft (MS) Excel are often considered to be an integral way of investigating how your company is progressing?

# re: Processing an Excel upload with nServiceBus 1/18/2011 3:08 PM nike vr pro
What a wonderful idea. Art can not hide from people. It was created for the public!

# re: Processing an Excel upload with nServiceBus 1/28/2011 7:22 AM Hydrolyze
Great article. Thank you for your  informative post.


# re: Processing an Excel upload with nServiceBus 1/28/2011 7:23 AM 31 Day Fat Loss Cure
I really liked the post and great tips..even I also think that hard work is the most important aspect of getting success keep it up :)


# re: Processing an Excel upload with nServiceBus 1/28/2011 7:25 AM dubturbo
Thank you for this information.On navigation you have given useful knowledge keep it up.:)


# re: Processing an Excel upload with nServiceBus 2/25/2011 5:34 AM infant crib mattress reviews
thanks for the interesting post.

# re: Processing an Excel upload with nServiceBus 2/25/2011 5:35 AM best organic crib mattress
nice article .keep it up guys..

# re: Processing an Excel upload with nServiceBus 2/25/2011 5:36 AM standard crib mattress size
great post.

# re: Processing an Excel upload with nServiceBus 2/25/2011 7:17 AM vdscvcv
Of course, what a great site and advisory posts, Can I add backlink - import your rss feed? Regards, Reader.
31 Day Fat Loss Cure Scam


# re: Processing an Excel upload with nServiceBus 2/25/2011 7:18 AM 31 Day Fat Loss Cure Review
Hi this is Jenny, am from Florida. I am here to have some fun with mah friends


# re: Processing an Excel upload with nServiceBus 2/25/2011 7:19 AM 31 day fat loss cure
Thanks a lot for discussing this information, I do not know about anyone else, but I can totally use it.


# re: Processing an Excel upload with nServiceBus 3/2/2011 6:47 AM defdsfd
You know so much about this subject, made me think about it from so many different angles. Its like people arent interested unless it has something to do with Lady Gaga! Your stuffs great.
organic crib mattress reviews
crib mattress size


# re: Processing an Excel upload with nServiceBus 3/19/2011 9:33 PM Notebook
Google recently stopped development on Notebook, which means it's no longer open to sign-ups by new users or being improved. Directed by Nick Cassavetes. With Gena Rowlands, James Garner, Rachel McAdams, Ryan Gosling.Circus Ponies NoteBook is the award-winning Mac application for getting organized on OS X. De-clutter your Desktop, track your tasks, manage your projects,

# re: Processing an Excel upload with nServiceBus 3/23/2011 7:14 AM 31 day fat loss cure review
I was looking for this information from long time and found your post. It will be very useful for me. Thanks and keep it up.


# re: Processing an Excel upload with nServiceBus 3/23/2011 7:17 AM 31 day fat loss cure scam
thanks for the nice articles.

# re: Processing an Excel upload with nServiceBus 3/25/2011 4:21 AM New York Yankees hats
Thanks for sharing!

# re: Processing an Excel upload with nServiceBus 4/12/2011 10:03 AM how to hack the stock market
Wonderful solutions.Id like to suggest taking a look at things like sausages. What are your thoughts?


# re: Processing an Excel upload with nServiceBus 4/12/2011 10:05 AM no nonsense muscle building
This is a appealing post by the way. I am going to go ahead and bookmark this post for my sister to read later on tonight. Keep up the fine work.


# re: Processing an Excel upload with nServiceBus 4/19/2011 12:04 AM unfaithful partner
These are so advanced tricks...

# re: Processing an Excel upload with nServiceBus 4/24/2011 11:56 PM search court records
Great tricks, I will surely make use of them

# re: Processing an Excel upload with nServiceBus 6/5/2011 12:43 AM London Escorts
we will come back to see if you have any follow up to this ;-) Indian escorts London

# re: Processing an Excel upload with nServiceBus 6/8/2011 9:29 AM nabiha hayat

You are fantastic as your work and I really think that this is a good topic to share send flower uk

# re: Processing an Excel upload with nServiceBus 6/11/2011 5:39 PM ceh
No doubt The information presented is quite useful. By using this I think all can prevent major breakdown


# re: Processing an Excel upload with nServiceBus 6/11/2011 5:41 PM jam
Fantastic precise info and this is one of the most nice blogs Ive read in a very long time ceh | xbox live codes




# re: Processing an Excel upload with nServiceBus 6/18/2011 9:37 AM freetress
Thanks a lot for sharing all the information with us
Thanks, thanks, thanks..

# CuteAnjeli 6/28/2011 11:43 AM send flowers to lebanon
It is very interesting for me to read that article. Thank author for it. I like such topics and everything connected to this matter. I definitely want to read more soon. send flowers to lebanon || flowers to ireland

# re: Processing an Excel upload with nServiceBus 7/25/2011 7:12 AM Heathrow Taxi
NServiceBus is a powerful, yet lightweight, open source messaging framework for designing distributed .NET enterprise systems. It gives programmers a head-start on developing robust, scalable, and manta.

# re: Processing an Excel upload with nServiceBus 8/3/2011 7:45 AM Rack-Mount Monitor
NServiceBus is an open source enterprise service bus implementation in .NET. The core features of NServiceBus are the messaging capabilities. It also supports a long-running message exchange pattern called a saga. When it comes to saga support, NServiceBus comes with a Saga base class, templated by the saga data type. Saga data type contains the data about the state of the long-running message exchange orchestration process.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: