简体   繁体   English

使用String主键在mysql表上进行多线程插入和更新的最佳方法?

[英]Best way for multi-threaded inserts and updates on a mysql table with String primary key?

It seems like a simple question, but I am not able to figure out the best possible solution to this problem. 看来这是一个简单的问题,但我无法找出解决此问题的最佳方案。 I have a multithreaded as well as multiprocessing framework with reasonable concurrency(6-7 threads over 3 machines). 我有一个多线程以及具有合理并发性的多处理框架(3台机器上有6-7个线程)。 Each process either inserts into or updates the same table which has a string field as the primary key. 每个进程都将插入或更新具有字符串字段作为主键的同一张表。 What will be the best possible way to ensure a thread-safe execution and avoid deadlocks ? 确保线程安全执行并避免死锁的最佳方法是什么?

Any help will be greatly appreciated. 任何帮助将不胜感激。

thanks, Amit 谢谢阿米特

You could append the queries into a Redis set from multiple threads. 您可以将查询从多个线程追加到Redis集。 Then in another single thread to manage these queries into two (one insert and one update) and do the db operation from that thread. 然后在另一个线程中将这些查询分为两个(一个插入和一个更新)进行管理,并从该线程执行db操作。 Then the deadlock can be avoided. 这样就可以避免死锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM