开发者

Multiple insert (50-100+) in mysql table while online is a good practice?

开发者 https://www.devze.com 2023-04-11 03:08 出处:网络
I am dealing with a situation when my system inserts dynamically multiple entry in db table,it could be 1, 2 or may be 100 or may be more, this is achieved using a ajax call which while insertion will

I am dealing with a situation when my system inserts dynamically multiple entry in db table,it could be 1, 2 or may be 100 or may be more, this is achieved using a ajax call which while insertion will display a loader image to user who has made this action.

So , my question: Is this the good practice to make this insert online and keep the user looking at loader image or shall we collect the data somewhere and use a cron jo开发者_Go百科b later when user is offline....

Please give some suggestion on this...


I would say the answer here is "it depends". If you need the user to be aware of the data changes that they have made i.e. they might want to see the changes that have been made in the database rather than a "please wait until CRON job has run" notice then the answer is "yes" you should make the insert online.

If it is acceptable (from a user experience point of view) to have the data inserted at a later point in time i.e. offline via a CRON job as you describe, then it might be acceptable to run the update offline. Though personally I would only do this when dealing with larger data volumes than the ones you are describing.

if the size of the insert is limited to around 100 max then the user should not have to wait that long for the insert to run online (though it does depend on the target database for the insert). One suggestion here if the insert is taking a long time (and hence the user has to wait a while looking at the loader image) is to examine why the insert is taking so long. If you tune the insert so that it runs quickly then you'll get the best of both worlds: a good user experience and correct state in the database.

Hope that helps.


Inserting 100 rows is nothing for a database. It mostly depends on the rate at which those 100 rows come along. If this approaches several thousand rows in a concurrent fashion, or the content of the rows is extremely large (effectively putting pressure on the network or IO subsystem) then it can become a problem. But I would not worry about it.

I assume that actually loading and displaying the waiting image takes longer than such an insert operation to the DB (at least that's my experience, with a DB inserting about 150Hz 24/7).

0

精彩评论

暂无评论...
验证码 换一张
取 消