views:

80

answers:

3

Hi all,

I have a website where the user can upload an excel spreadsheet to load data in a table. There can be a few 100k rows in the excel spreadsheet. When he uploads the file the website needs to insert an equal amount of rows in a database table.

What strategy should i take to do this? I was thinking of displaying a "Please wait page" until the operation is completed but i want him to be able to continue browsing the website. Also, since the database at that time will be kind of busy - wouldn't that stop people from working on the website?

My data access layer is in NHibernate.

Thanks, Y

+4  A: 

Displaying a please wait page would be pretty unfriendly as your user could be wating quite a while and would block threads on your web server.

I would upload the file, store it and create an entry in a queue (you'll need anouther table for this) to indicate that there is a file waiting to be processed. You can then have another process (which could even run on it's own server) which picks up tasks from this queue table and processes the xls file in it's own time.

Steve Haigh
Thanks - could I create another thread that loads the data in the table? Like the user uploads the file and returns to the website immediately while another thread loads the data in the database.
Yannis
+1 One of the added benefits of this is that it will help you manage the peak load on your database
AdaTheDev
@Yannis - I'd actually write a separate process. Keep the DB upload completely separate from your website. You could do it on another thread, but I don't think there is much to gain there, it would be easier to do it completely seperately.
Steve Haigh
+1 Having a different process doing this processing is definitely the way to go. And since it can even be on another server, it really scales up.
Fabricio Araujo
one more question - having it on a different process is fine but how on earth would i give feedback back to the user waiting on a website? i would have to write something to some table or something that its only purpose is to keep the progress of data operations
Yannis
yes, exactly that. When the insert job is done you would clear the item from the queue, and the UI would need to check this.
Steve Haigh
Nice - thanks everyone
Yannis
And of course, do not load these records one at a time. Use a bulk insert process. That should take less than a minute anyway.
HLGEM
+1  A: 

I would create an upload queue that would submit this request to. Then the user could just check in on the queue every once in a while. You could store the progress of the batch operation in the queue as the rows are processed.

Also, database servers are robust, powerful, multi-tasking systems. Unless you have observed a problem with the website while the inserts are happening don't assume it will stop people from working on the website.

However, as far as insert or concurrent read/write performance goes there are mechanisms to deal with this. You could use the "INSERT LOW PRIORITY" syntax in MySQL or have your application throttle the inserts by sleeping a millisecond between each insert. Also, how you craft your insert statements, wether you use bound parameters or not, and wether you use multi-valued inserts can affect the insert performance and how it affects clients to a large degree.

bot403
A: 

On Submit you could pass the DB Operation to a asynchronous RequestHandler and set a Session Value when its done.

While the asynch process is in progress you can check the Session Value on each request and if it is set (operation = completed) display a message, eg in a modal or whatever message mechanism you have.

ovm