Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simultaneously Transactions with web workers and main app #3

Open
fishme opened this issue May 10, 2017 · 8 comments
Open

Simultaneously Transactions with web workers and main app #3

fishme opened this issue May 10, 2017 · 8 comments

Comments

@fishme
Copy link

fishme commented May 10, 2017

Hi Chris,

I was playing around with the web workers.

My use case needs to run sql commands in the web worker and to the same time sql commands in the main app.
But this runs in a critical issue.

error

Maybe I do something wrong, I created a small repo with this use case: https://github.com/fishme/sqlite-cordova-webworker-test

How to reproduce:
Tap fast between "Show record count" and "run webworker"
The web worker insert 10.000 records.

Tested: Android 6.0 (nexus 5x)

Maybe you have an idea, how to do it? Or is that principle not possible?

Best David

@brodycj
Copy link
Member

brodycj commented May 11, 2017

Thanks @fishme this is definitely a bug. The root cause is that there is a transaction queue in the main JavaScript thread and another transaction queue in the web worker.

The workaround is to use database.executeSql (for SELECT and single-statement changes) and database.sqlBatch (for multi-statement changes) instead of database.transaction.

I may would like to deprecate the existing database.transaction mechanism in this version due to this issue.

@fishme
Copy link
Author

fishme commented May 12, 2017

hi @brodybits

thanks for your feedback. Well but how is the performance if I run every single sql command into .executeSql, without a transaction?
I was testing it with a simple loop and then .executeSql and it took much longer as before.
For 10-20 calls it is ok, I guess, but for 10k and more?
Also callback handling can be tricky.

Or do I see here something wrong?

Best David

@brodycj
Copy link
Member

brodycj commented May 12, 2017

Hi David,

Please be sure to use database.sqlBatch to insert a large number of records. The code you wrote in https://github.com/fishme/sqlite-cordova-webworker-test/blob/master/www/webworker/sample-worker.js#L6 is correct. Then you should use database.executeSql to SELECT (read) data from the database.

Please report if this helps or not.

@brodycj
Copy link
Member

brodycj commented Oct 26, 2017

Please be sure to use database.sqlBatch to insert a large number of records.

My apologies, sqlBatch is not supported by this plugin version yet. Hope to add it soon.

@brodycj
Copy link
Member

brodycj commented Dec 31, 2017

My apologies, sqlBatch is not supported by this plugin version yet. Hope to add it soon.

sqlBatch support was rolled in by merge ref: #4

@brodycj
Copy link
Member

brodycj commented Jan 18, 2018

sqlBatch support was rolled in by merge ref: #4

Using sqlBatch still does not solve this issue since it works in multiple batches.

Probably the best solution would be parallel database access handles, similar to the parallel database readers solution in https://github.com/brodybits/cordova-sqlite-evmax-legacy-exp-free. Issue with parallel reader/writer interference discussed in brodycj/cordova-sqlite-evmax-legacy-exp-free#1 would need to be solved on native platform side in this plugin version due to possible access from multiple JavaScript threads.

@fishme
Copy link
Author

fishme commented Jan 19, 2018

Thanks for the update I will do some tests the next days

@brodycj
Copy link
Member

brodycj commented Feb 4, 2018

@fishme this is still an issue. I am planning to resolve this issue by using parallel database access handles (#8), hopefully within the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants