Closed manojsharma20 closed 6 years ago
You can lock tables in MySQL. Is this what you are after?
No, I don't want to mysql end. I want it on node server. as i have mentioned my table will receive 100 record per second and so 100 event will be fire against each insert.
mysql-events modele which great suited for my requirement. I just want that if first event fire and receive the same and delay any new mysql event execution until first one finished. here is my code:
var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io').listen(http); var mysql = require('mysql'); var MySQLEvents = require('mysql-events');
var dsn = { host: 'localhost', user: 'root', password: '' };
var mysqlConn = mysql.createPool({ host: 'localhost', port: 3306, user: 'root', password: '', database: 'tester' }); var myCon = MySQLEvents(dsn);
http.listen(3000, function(){ console.log('Listening on Port 3000'); });
function myFunction(oldRow, newRow){
console.log("==================================== log receving ==============================================");
if(newRow !== null){
mysqlConn.query("select count() as total from table1
"
, function(err, rows, fields) {
if (err) throw err;
mysqlConn.query("select count() as total1 from table1
where date(ReceivedAt) = CURDATE()", function(err1, rows1, fields1){
if (err) throw err1;
mysqlConn.query(" select count(*) as total2 from table1
where DATE_FORMAT(ReceivedAt,'%Y-%m-%d %H') = DATE_FORMAT(CURRENT_TIMESTAMP(),'%Y-%m-%d %H')", function(err2, rows2, fields2){
if (err) throw err2;
var data = {
data1: newRow.fields,
total1: rows[0].total1,
total2: rows1[0].total2,
total3: rows2[0].total3
};
return data;
});
});
});
}
}
io.sockets.on('connection', function (socket) { // socket.emit('welcome', { hello: 'world' });
var event1 = myCon.add(
'test.tester',
function (oldRow, newRow) {
Sync(function(){
var data = myFunction.sync(oldRow, newRow);
socket.emit(channel', data);
console.log(newRow.fields); console.log("================================================================================");
})
}
);
});
Now, i want whatever i have written inside event it accomplished first before next event execution and next all event should be queue until first one finished.
Are you doing individual INSERT
s or are you using START TRANSACTION
and COMMIT
?
Hi,
I am able to receive the events when these events are in 1 second 1 event only, but when i am receiving 100 events per second then nothing is showing due to the volume.
I there any way to sync or do the locking kind of thing like we do the same in any programming language.