删除Solr服务器上的updateLog(Remove updateLog on Solr server)
我注意到当我禁用updateLog时(通过从solrconfig.xml中删除它),索引速率提高了25%。
服务器是独立的,我们没有使用原子更新。
我想知道是否有其他副作用或功能会破坏。I've noticed that there is 25% improvement in indexing rate when I disable the updateLog (by removing it from solrconfig.xml).
The server is standalone and we are not using atomic update.
I was wondering if there are other side effects or features which will break.
原文:https://stackoverflow.com/questions/37568621
最满意答案
对于在同一个表上运行50到100个并发进程的系统,我对此进行了大量的研究和实验。 除了基本的死锁之外,还有许多事务失败。 我的案例包括read committed和serializable事务。 在应用程序级别处理此问题并不会导致任何问题。 幸运的是Postgres会立即失败,所以唯一的性能打击是应用程序,对数据库没有任何重要意义。
关键组件是捕获每种类型的错误 ,知道哪些情况需要回滚,并具有重试的指数退避 。 我发现立即重试或静态睡眠时间会导致进程重复地相互死锁并引起一些多米诺骨牌效应,这是有道理的。
这是我的系统处理每个并发问题(伪代码)所需的完整逻辑:
begin transaction (either read committed or serializable) while not successful and count < 5 try execute sql commit except if error code is '40P01' or '55P03' # Deadlock or lock not available sleep a random time (200 ms to 1 sec) * number of retries else if error code is '40001' or '25P02' # "In failed sql transaction" or serialized transaction failure rollback sleep a random time (200 ms to 1 sec) * number of retries begin transaction else if error message is 'There is no active transaction' sleep a random time (200 ms to 1 sec) * number of retries begin transaction increment count
I did a lot of research and experimentation into this for a system that's running 50 to 100 concurrent processes on the same tables. There are a number of transaction failures that can happen besides basic deadlocks. My case includes both read committed and serializable transactions. There's no situation where handling this at the application level caused any issues. Fortunately Postgres will fail immediately, so the only performance hit is to the application, nothing significant to the database.
The key components are catching every type of error, knowing which cases require a rollback, and having an exponential backoff for retries. I found that immediate retries or static sleep times cause processes to simply deadlock each other repeatedly and cause a bit of a domino effect, which makes sense.
This is the complete logic my system requires to handle every concurrency issue (pseudocode):
begin transaction (either read committed or serializable) while not successful and count < 5 try execute sql commit except if error code is '40P01' or '55P03' # Deadlock or lock not available sleep a random time (200 ms to 1 sec) * number of retries else if error code is '40001' or '25P02' # "In failed sql transaction" or serialized transaction failure rollback sleep a random time (200 ms to 1 sec) * number of retries begin transaction else if error message is 'There is no active transaction' sleep a random time (200 ms to 1 sec) * number of retries begin transaction increment count
相关问答
更多-
通过PHP检测MySQL死锁(MySQL Deadlock Detection via PHP)[2023-04-01]
死锁返回错误1213 ,您应该在客户端进行处理 请注意,死锁和锁等待是不同的事情。 在僵局中,没有“失败”的交易:他们都有罪。 无法保证哪一个会回滚。 在这种情况下发生死锁: UPDATE t_first -- transacion 1 locks t_first SET id = 1; UPDATE t_second -- transaction 2 locks t_second SET id = 2; UPDATE t_second -- transaction 1 waits ... -
唯一不能真正放入varchar的是0x00,因为这是一个字符串终止符。 0x04工作正常,就像其他不可打印的字符一样。 The only thing you can not really put into varchar is 0x00, as this is a string terminator. 0x04 works just fine, just like other non-printable characters.
-
依靠Postgres的死锁检测进行并发控制是否安全?(Is it safe to rely on Postgres' deadlock detection for concurrency control?)[2023-07-28]
对于在同一个表上运行50到100个并发进程的系统,我对此进行了大量的研究和实验。 除了基本的死锁之外,还有许多事务失败。 我的案例包括read committed和serializable事务。 在应用程序级别处理此问题并不会导致任何问题。 幸运的是Postgres会立即失败,所以唯一的性能打击是应用程序,对数据库没有任何重要意义。 关键组件是捕获每种类型的错误 ,知道哪些情况需要回滚,并具有重试的指数退避 。 我发现立即重试或静态睡眠时间会导致进程重复地相互死锁并引起一些多米诺骨牌效应,这是有道理的。 这 ... -
Postgres的增量是否触发原子和高并发安全?(Are increments with Postgres triggers atomic and high concurrency safe?)[2024-02-08]
这并不奇怪。 now()返回事务开始的时间。 无法保证首先启动的事务将是第一个执行触发器的事务。 使用该版本确定更新的顺序。 That is not surprising. now() returns the time when the transaction started. There is no guarantee that the transaction that starts first will be the first one to perform the trigger. Use the v ... -
你不需要任何明确的LOCK进入死锁。 这里是一个非常简单的演示,从头开始只有INSERT: create table a(i int primary key); create table b(i int primary key); 会议#1确实: begin; insert into a values(1); 然后,会话#2会: begin; insert into b values(1); insert into a values(1); -- here it goes into waiting fo ...
-
死锁检测可以在更高级别完成,对于进程,死锁检测可以在操作系统级别完成,对于线程,主线程可以检测子线程之间的死锁,如果子线程不需要任何系统级资源I / O等 检测死锁的一种方法是为共享资源构建资源需求图。 假设系统创建了2个线程Ta和Tb,Ta和Tb都需要资源Ra和Rb。 如果Ta已经获得了Ra,并且需要Rb,则这可以像有向图:Ra-> Ta-> Rb。 如果Tb持有Rb,这将类似于Ra-> Ta-> Rb-> Tb,没有死锁。 但是,如果Tb持有Rb并且需要Ra,则图形将如下:Ra-> Ta-> Rb-> ...
-
在Rails代码中应该注意哪些类型的并发/死锁问题?(What kinds of concurrency/deadlock issues should one be aware of in Rails code?)[2023-11-08]
死锁意味着对I / O资源的竞争,这就是为什么它最常出现在数据库中。 如果你不正确地锁定和请求资源,并且你明确地使用线程,那么你需要关心。 但是,缓解任何问题的具体步骤取决于您访问的I / O类型。 Deadlock implies competition for an I/O resource, which is why it comes up for databases most often. If you're improperly locking and requesting resources a ... -
死锁检测(Deadlock Detection)[2023-07-09]
当您处理状态为“有A,需要B”而其他一些进程处于“有B,需要A”时,会发生死锁。 如果我正确地读你的表,那么这将表明一个僵局: Allocation Request Available A B C A B C A B C P0 0 1 0 1 0 0 0 0 0 P1 2 0 0 2 1 2 P0具有资源B,并且需要资源A,没有更多资源A可用 P1有2个资源A,需要源B,没有更多的B可用。 在更多资源A ... -
Postgres只会发现死锁,如果它可以看到两个交易相互等待。 特别是对于两个(或更多)进程,场景必须是: 需要获取被B锁定的资源。 B需要获取被A锁定的资源。 死锁处理不会处理以下情况: 需要获取被B锁定的资源。 B将表锁定在交互式psql会话中,然后在没有提交,回滚或注销的情况下休息。 根据您的描述,听起来您的某个数据库会话未释放其资源。 也许它缺少一个COMMIT等。就Postgres而言,它并不是一个僵局,因为众所周知,有一个完全正确的理由,为什么锁被持有那么久。 您可以做的一件事是设置锁定超时。 ...
-
Postgres僵局(Postgres deadlock)[2023-10-09]
(这是一个猜想,但希望是受过教育的人。) 一切都取决于SELECT被ORID BY O_ID ... FOR UPDATE锁定行的顺序。 如果O_ID的顺序与ID的顺序不同,那么完全有可能出现类似这样的情况: ID O_ID -- ---- 1 2 2 1 事务A锁定ID = 2的行。 事务B锁定ID = 1的行。 事务A尝试锁定ID = 1的行,但强制在事务B上等待。 事务B尝试锁定ID = 2的行,但强制等待事务A. 警告:即使O_ID顺序与ID顺序相同,ORDER BY子 ...