diff options
author | stephan <stephan@noemail.net> | 2022-11-21 05:18:24 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-11-21 05:18:24 +0000 |
commit | b38ac0986e86d56115396c36355d4e751cc4f7f5 (patch) | |
tree | 33d263ac06b881ac99bad30730d42a62543b7f94 /ext/wasm/tests | |
parent | 36d5554c9abaa3080e85e3b7b517605c6106587d (diff) | |
download | sqlite-b38ac0986e86d56115396c36355d4e751cc4f7f5.tar.gz sqlite-b38ac0986e86d56115396c36355d4e751cc4f7f5.zip |
More tweaking of OPFS concurrency measures and the related test app.
FossilOrigin-Name: a8d4da1501d411085ec2fd48c4a056c8b1d97ef3c3203c5b403a854ac2864870
Diffstat (limited to 'ext/wasm/tests')
-rw-r--r-- | ext/wasm/tests/opfs/concurrency/index.html | 16 | ||||
-rw-r--r-- | ext/wasm/tests/opfs/concurrency/test.js | 9 | ||||
-rw-r--r-- | ext/wasm/tests/opfs/concurrency/worker.js | 46 |
3 files changed, 49 insertions, 22 deletions
diff --git a/ext/wasm/tests/opfs/concurrency/index.html b/ext/wasm/tests/opfs/concurrency/index.html index 79a46692c..a082dfe99 100644 --- a/ext/wasm/tests/opfs/concurrency/index.html +++ b/ext/wasm/tests/opfs/concurrency/index.html @@ -18,7 +18,21 @@ <h1></h1> <p> OPFS concurrency tester using multiple independent Workers. - This app is incomplete. + Disclaimer: concurrency in OPFS is currently a pain point + and timing/concurrency mitigation in this environment is + highly unpredictable! + </p> + <p> + URL flags: pass a number of workers using + the <code>workers=N</code> URL flag and the worker work interval + as <code>interval=N</code> (milliseconds). Enable OPFS VFS + verbosity with <code>verbose=1-3</code> (output goes to the + dev console). + </p> + <p>Achtung: if it does not start to do anything within a couple of + seconds, check the dev console: Chrome often fails with "cannot allocate + WasmMemory" at startup. Closing and re-opening the tab usually resolves + it. </p> <div class='input-wrapper'> <input type='checkbox' id='cb-log-reverse'> diff --git a/ext/wasm/tests/opfs/concurrency/test.js b/ext/wasm/tests/opfs/concurrency/test.js index b80dad24c..8b75ea4c7 100644 --- a/ext/wasm/tests/opfs/concurrency/test.js +++ b/ext/wasm/tests/opfs/concurrency/test.js @@ -57,6 +57,12 @@ options.workerCount = ( urlArgsHtml.has('workers') ? +urlArgsHtml.get('workers') : 3 ) || 3; + options.opfsVerbose = ( + urlArgsHtml.has('verbose') ? +urlArgsHtml.get('verbose') : 1 + ) || 1; + options.interval = ( + urlArgsHtml.has('interval') ? +urlArgsHtml.get('interval') : 750 + ) || 750; const workers = []; workers.post = (type,...args)=>{ for(const w of workers) w.postMessage({type, payload:args}); @@ -91,7 +97,8 @@ workers.uri = ( 'worker.js?' + 'sqlite3.dir='+options.sqlite3Dir - + '&opfs-verbose=2' + + '&interval='+options.interval + + '&opfs-verbose='+options.opfsVerbose ); for(let i = 0; i < options.workerCount; ++i){ stdout("Launching worker..."); diff --git a/ext/wasm/tests/opfs/concurrency/worker.js b/ext/wasm/tests/opfs/concurrency/worker.js index 9aaa2f4c7..85a5cf19b 100644 --- a/ext/wasm/tests/opfs/concurrency/worker.js +++ b/ext/wasm/tests/opfs/concurrency/worker.js @@ -8,7 +8,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ }; const stdout = (...args)=>wPost('stdout',...args); const stderr = (...args)=>wPost('stderr',...args); - const postErr = (...args)=>wPost('error',...args); if(!sqlite3.opfs){ stderr("OPFS support not detected. Aborting."); return; @@ -19,15 +18,33 @@ self.sqlite3InitModule().then(async function(sqlite3){ }; const dbName = 'concurrency-tester.db'; - if((new URL(self.location.href).searchParams).has('unlink-db')){ + const urlArgs = new URL(self.location.href).searchParams; + if(urlArgs.has('unlink-db')){ await sqlite3.opfs.unlink(dbName); stdout("Unlinked",dbName); } wPost('loaded'); - + let db; + const interval = Object.assign(Object.create(null),{ + delay: urlArgs.has('interval') ? (+urlArgs.get('interval') || 750) : 750, + handle: undefined, + count: 0 + }); + const finish = ()=>{ + if(db){ + if(!db.pointer) return; + db.close(); + } + if(interval.error){ + wPost('failed',"Ending work after interval #"+interval.count, + "due to error:",interval.error); + }else{ + wPost('finished',"Ending work after",interval.count,"intervals."); + } + }; const run = async function(){ - const db = new sqlite3.opfs.OpfsDb(dbName,'c'); - //sqlite3.capi.sqlite3_busy_timeout(db.pointer, 2000); + db = new sqlite3.opfs.OpfsDb(dbName,'c'); + sqlite3.capi.sqlite3_busy_timeout(db.pointer, 5000); db.transaction((db)=>{ db.exec([ "create table if not exists t1(w TEXT UNIQUE ON CONFLICT REPLACE,v);", @@ -36,11 +53,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ }); const maxIterations = 10; - const interval = Object.assign(Object.create(null),{ - delay: 500, - handle: undefined, - count: 0 - }); stdout("Starting interval-based db updates with delay of",interval.delay,"ms."); const doWork = async ()=>{ const tm = new Date().getTime(); @@ -57,15 +69,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ interval.error = e; } }; - const finish = ()=>{ - db.close(); - if(interval.error){ - wPost('failed',"Ending work after interval #"+interval.count, - "due to error:",interval.error); - }else{ - wPost('finished',"Ending work after",interval.count,"intervals."); - } - }; if(1){/*use setInterval()*/ interval.handle = setInterval(async ()=>{ await doWork(); @@ -89,7 +92,10 @@ self.sqlite3InitModule().then(async function(sqlite3){ self.onmessage = function({data}){ switch(data.type){ - case 'run': run().catch((e)=>postErr(e.message)); + case 'run': run().catch((e)=>{ + if(!interval.error) interval.error = e; + finish(); + }); break; default: stderr("Unhandled message type '"+data.type+"'."); |