7

I am developing a web-based interface for a hardware sensor that produces approx. 250kB/s of raw data (125 kS/s, 16 bit per sample). The web application is designed to visualize (using Canvas) and store (using IndexedDB) this data in real-time. I am having performance issues with indexedDB storage.

This application is designed to run for days or even weeks and should reliably store large amounts of data (tens to the low hundreds of MB)

Because write commits seem to be the general performance issue, I have rewritten my application to only store a big chunk of data every 5 seconds as a non-sparse integer array object. This kind of works, but I still get very choppy visualization performance, high CPU and high memory usage. The exact storage code:

//dataDB = indexedDB database opened in another function
//slice = data to be stored
//sessionID = object store index 

//this function is called about once every 5 seconds
//with 700 000 values in the slice array
//slice is a multidimensional array

function storeFastData(slice, sessionID){
    var s = dataDB.transaction(["fastData"],"readwrite").objectStore("fastData");
    var fdreq = s.get(sessionID);
    fdreq.onsuccess = function(e){
        var d = fdreq.result;
        for(i = 0; i < slice.length; i++){
            d.data[i][1] = slice[i][1];
        }
        s.put(d);
    }
}

Concretely:

  • Is IndexedDB the right choice for this application?
  • Am I being an idiot in the way I implemented this? This is the first IndexedDB-based project I am doing
  • I have read that using WebWorkers may at least fix the stuttering issues as it can run on another thread. Would this solve my performance problems?

I am willing to use new (draft) functionality, but requiring user interaction for storage beyond 5MB (e.g. using Quota Management API) every time the application is opened, is quite bothersome and if at all possible I would like to avoid this.

I do not use jquery. This cannot be written as a native application (it has to run inside a browser).

3
  • Would you be willing to consider writing a Chrome plugin? It naturally provides a background page to offload some processing so there is no need for a web worker, and it avoids any quota cap if you use the unlimited permission.
    – Josh
    Commented Jun 9, 2015 at 5:03
  • 4
    No, a chrome plugin would defeat the purpose of having it web-based. Chrome isn't the only browser around, and probably won't exist in 5 years anymore (or at least, if trends continue as they do, it will be replaced by something else).
    – user36129
    Commented Jun 9, 2015 at 6:57
  • For the record (1.5 years later): You can use the FileSystem API in Chrome - and only in Chrome, and it is no longer developed so won't appear in other browsers (in that form). Other than that IndexedDB indeed seems to be the only option, and an unreliable one since all data stored in it can disappear at any time if the browser decides so. So there really isn't any other (or any) good solution.
    – Mörre
    Commented Jan 26, 2017 at 16:07

1 Answer 1

0

IndexedDB is excellent choice for your case. If you store as soon as data are available quickly and frequently, it should be OK. You don't wait for 5 sec, store right away around 200 ms interval. Generally an indexeddb write op takes 20ms.

Not the answer you're looking for? Browse other questions tagged or ask your own question.