Giter VIP home page Giter VIP logo

Comments (4)

nolanlawson avatar nolanlawson commented on June 23, 2024 1

In the current implementation, write starvation is not a problem because
reads don't jump the queue. I see what you mean about the performance
issues and agree there should be one read transaction to bookend all the
reads.

As a side note, I am incredibly busy these days and am unlikely to have
time to submit a fix, but PRs would be welcome. :)

from node-websql.

nolanlawson avatar nolanlawson commented on June 23, 2024

Currently I do a soft transaction -- i.e. doing all the reads at once outside of a transaction, and guaranteeing no writes using a queue.

Technically this is incorrect if there is more than one user of the system, but I also assumed only one user at a time. You are right that there should be a global read transaction while all reads are being made, but it only matters if there is more than one reader from more than one thread. I don't see this as a very high-priority task but it would hew closer to the spec, yes.

from node-websql.

brettz9 avatar brettz9 commented on June 23, 2024

The greater significance of the read lock, as I see it, is to ensure no writes occur during the read transaction, and that the "shared" nature of the lock means that subsequently initiated read transactions be allowed to overlap with this one--another read transaction could begin or even end while the first read transaction may yet be ongoing.

My concern is thus less with any independent processes that may be operating on the same database, than with the performance problem of all of the read transactions being done currently in series (with an "immediate" timeout in between each (read) transaction), potentially impacting performance within a single thread.

Take this code for example:

var openDatabase = require('websql');
var db = openDatabase(':memory:', '1.0', 'description', 1);
db.transaction(function (t) {
    t.executeSql('CREATE TABLE docids (id, name)', [], function (t) {
        for (var i = 0; i < 10; i++) {
            t.executeSql('INSERT INTO docids (id, name) VALUES (' + i + ', "' +
                String.fromCharCode(i + 97) + '")');
        }
    });
}, null, beginReads);

function beginReads () {
    for (var i = 0; i < 100; i++) {
        (function (i) {
            db.readTransaction(function (t) {
                t.executeSql('SELECT name FROM docids WHERE id = ' + i, [], function (data) {
                    console.log('Finished: ' + i);
                }, function (tx, err) {
                    console.log(err);
                });
            });
        }(i));
    }
}

The logging for "Finished:" will always show the count in order although this, as I understand the spec in reference to "shared" read locks, should not be necessary since I don't see any requirement that subsequent (read) transactions must wait for previous (read) transactions to complete.

(Providing the optimization should not allow write "starvation", however, whereby writes could be indefinitely prevented from occurring or occurring in a timely fashion if reads were always allowed to begin while another read was in process, and there were an ongoing supply of reads).)

from node-websql.

nolanlawson avatar nolanlawson commented on June 23, 2024

Closing old issues, please reopen as necessary

from node-websql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.