Comments (4)
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.
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.
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.
Closing old issues, please reopen as necessary
from node-websql.
Related Issues (20)
- Usage with sql.js HOT 2
- Add a fix for browsers not able to readTransaction on first transaction with virtual tables HOT 1
- Configuration HOT 2
- Illegal Invocation on initializing new sqlite db with node-websql HOT 2
- Mention, if not workaround, surfaced node-sqlite3 database restrictions HOT 1
- Run readTransactions more efficiently HOT 2
- Support the WebSQL synchronous API HOT 1
- Update to sqlite3 4.0.0 (for security if nothing else)
- SQL.js HOT 1
- Consider better-sqlite3 as an alternative to node-sqlite3 HOT 2
- Prepare statements under the hood HOT 3
- Can't module resolve 'websql' in typescript HOT 1
- how to use webpack to run it on browser HOT 4
- update sqlite3 to ^5.0.2
- Errors thrown from async statement success callbacks are not treated as per spec
- Transactions auto-close when queuing microtasks between executeSql() calls HOT 13
- ⚠️ Web SQL is deprecated HOT 1
- CTE (WITH clause) is not working ('SELECT' is required to begin a query; otherwise, no results are returned)
- Feature request flash polyfill HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-websql.