Unexpected Slow Performance When Using Sequelize with MySQL for Bulk Inserts
I'm stuck on something that should probably be simple. I keep running into Hey everyone, I'm running into an issue that's driving me crazy. I'm working on a project and hit a roadblock. I'm experiencing significant slowdowns when performing bulk inserts using Sequelize (version 6.15.0) with MySQL (version 8.0.23). My current implementation is taking well over a minute to insert about 500 records, which seems excessive given the expected performance from a relational database. I’ve set up my Sequelize model like this: ```javascript const User = sequelize.define('User', { name: { type: Sequelize.STRING, allowNull: false, }, email: { type: Sequelize.STRING, allowNull: false, unique: true, }, }, { timestamps: false }); ``` When performing inserts, I'm using the following code: ```javascript const usersData = Array.from({ length: 500 }, (_, index) => ({ name: `User ${index + 1}`, email: `user${index + 1}@example.com`, })); await User.bulkCreate(usersData, { returning: true }); ``` I’ve tried disabling the `returning` option, which did improve the speed slightly, but I still find the performance lacking. Additionally, I’ve verified that my MySQL server is not under heavy load and that connection pooling is configured properly. I also looked into the `autoIncrement` on IDs and the `transaction` feature, but those seem to complicate the process more than necessary. When I check the MySQL slow query log, I don't see any entries that would indicate problems with the query itself. However, I noticed that the insertion locks seem to be held longer than expected. Is there a more efficient way to handle bulk inserts in Sequelize when using MySQL? Any tips on improving this performance would be greatly appreciated! How would you solve this? The project is a microservice built with Javascript. Thanks in advance! Thanks for your help in advance! I've been using Javascript for about a year now. I'd really appreciate any guidance on this.