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

Observed huge memory spike on transactions #2

Open
harees opened this issue Apr 11, 2016 · 1 comment
Open

Observed huge memory spike on transactions #2

harees opened this issue Apr 11, 2016 · 1 comment

Comments

@harees
Copy link

harees commented Apr 11, 2016

We were trying to use sqlite workers to move our transaction to worker thread. We observed that, when we use db.transcations multiple times on iOS, the memory usage shots up unprecedentaly and reached upto 350 MB for simple insert/update and a select query in the end. Here is a sample code which simulates the actual code.

`importScripts('SQLitePlugin.js');

self.addEventListener('message', function(ev) {
if (ev.data === 'go') {
var i = 0;
sqlitePlugin.openDatabase({
name: 'testdb.db'
}, function(db) {
db.executeSql("Select Max(Prime) lastItem from test_table;", [], function(res) {
var nextRow = res.rows.item(0).lastItem + 1;
do {
i++;
nextRow++;
db.transaction(function(tx) {
var next=nextRow;
tx.executeSql("Update test_table set numberdata=2 where prime=?",[next],function(tx1, res) {
self.postMessage('Rows affected: ' + res.rowsAffected);
if (res.rowsAffected == 0)
tx.executeSql("Insert into test_table (numberdata)values(2)",[],function(tx1, res) {
if (i == 100) {
db.executeSql("Select Prime,NumberData from test_table;", [], function(res) {
self.postMessage('Final data: ' + res.rows.length.toString());
});
}
});
},function(error){

                                                      self.postMessage( JSON.stringify(error));
                                                      });

                                    });

                                      }while (i < 100);
                                      });

            });
                  }
                  }); `

Am I doing any thing wrong? Is there any better usage suggestions.

screen shot 2016-04-10 at 11 56 42 pm

[testdb.db.zip](https://github.com/litehelpers/cordova-sqlite-workers-evfree/files/212943/testdb.db.zip)
@brodycj
Copy link
Member

brodycj commented May 12, 2017

I will test this when I get a chance.

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