Answer the question
In order to leave comments, you need to log in
How suitable is the following code for heavy database operations?
I don't think the language matters much. Arrange the advice of Sharpists and those who write on Dart. The original Dart code. But I think it will be very clear to everyone.
Database db;
void main() async {
db = Database();
var pidFile = File("pid.txt");
pidFile.writeAsStringSync(pid.toString());
connection = PostgreSQLConnection('localhost', 5432, 'db', username: 'postgres', password: '123456', queryTimeoutInSeconds: 30);
await connection.open();
app.post('/db', (req, res) async {
var r = await db.someLongDBOperation(req.body);
return res.json({"data": r});
});
}
Answer the question
In order to leave comments, you need to log in
You can easily select a bunch of threads. In fact, async is a wrapper over the pool. Is the load steady or bursty?
Bottlenecks - this is actually a lot of queries to the database for insertion (possibly also into one table) - can slow down the database. Collect on the server in packs of the data and do periodically batch insert.
At each insert in the table it is locked and other requests for an insert wait + indexes are still rebuilt.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question