开发者

Best way to save a massive array on server side

I am currently working on a web-page in HTML5/Javascript, where the user can record the value of sliders changed in a period of time. For example, when the user click Record, a timer will start and every time the user move a slider, its value will be saved in an array. When the user stop the record and play, all sliders will then be 'played' as he recorded them. I store the value in an array, something like that:

array[3] : {timeStamp, idSlider, valueSlider}

The array can actually become pretty massive as the user can then record over the already recorded settings without losing the previous one, this allow the user to change multiple sliders for the same time 开发者_运维百科stamp.

I now want to be able to save this array somewhere (on server side), so the user can come back to the website later on, and just load its recorded settings, but I am not sure of the best approach to do that.

I am thinking of a dataBase, but not sure if this will be a bit slow to save and load from the server, plus my DataBase capacity is pretty small (around 25 Mo on my OVH server). I am thinking of maybe an average of 800 entries to save.

Maybe in a file (XML ?), but then I have no idea how to save that on my server-side...

Any other idea is welcome as I am a bit stuck on this one.

Thanks & sorry for any english mistakes, Cheers, Mat


Either serialize() or json_encode() it, save it as a longtext database record.

  • http://us.php.net/serialize
  • http://us.php.net/json-encode
  • http://dev.mysql.com/doc/refman/5.0/en/blob.html


I think 800 is not as massive as you think. You could just save it to a database and transfer it with JSON. I believe the database should be pretty efficient and not waste a lot of storage, but this can depend on how you setup your tables. Don't use char() columns, for example.

To see which uses more or less storage you could calculate how much space 1000 entries would take, then put them in the database and see how much space it uses and how much it's wasting.

If you really were dealing with a very large number of items then network performance will probably become your first bottleneck. For loading I would then stream javascript to the browser so that the browser doesn't have to load the whole thing into memory. Also, for sending you would want to create manageable chunks of maybe 1000 at a time and send them in these chunks. But, this is assuming you're dealing with more data.


You can try storing the whole json object as plain text in user-specific files. That would make serving the settings really easy, since it would be plain json that simple needs to be evaluated.

It seems a bit unorthodox though. When you say 800 entries do you mean 1. id : 0, timestamp : XXXXXXXXXXXXX, idSlider : X, etc 2. id : 1, timestamp : XXXXXXXXXXXXX, idSlider....

Or 800 user entries? Because you could save the whole object in the database as well and save yourself from executing lots of "costy" queries.


If you are concerned more about storage size than read/write performance you could encode the array as json string, compress it using zlib library and save it as a file.


This is a perfect use case for MongoDB.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜