Background work is performed twice while the same operation on rails

In my Rails application, I have a long calculation requiring a lot of database access.

To make it shorter, my calculation took 25 seconds.

When performing the same calculation in the background task (large single worker), the same calculation is performed twice at the same time (i.e. 50 seconds). I tried several techniques to put work in the background process, without adding influence to my actions => using DelayJob / Sidekiq / executing the process inside my rails, but in the thread created for work, but they all have the same effect on my performances * 2.

This performance difference exists only in the rails production environment. It seems that optimization is done using rails that are not performed in my background task.

My technical environment is as follows =>

  • I am using ruby ​​2.0 / rails 4
  • I use a unicorn (but I have the same problem without it).
  • The job uses Rails.cache to store partial calculations.
  • I am using postgresql

Does anyone have a clue where this effect might have come from?

+4
source share
3 answers

, -? , , , Rails QueryCache, db -. , :

SQL- Rails

, - , , . , ( ).

+1

- , . - " " 25 . , , , .

, - . , - .

, , , . , . . , , . , .

: , . , . - " " , , . , , , 25 .

0

, , . , , Rails . .

:

, :

  • .

.

, , .. , , Rails .

, 1 3 .

? : ? , , . , , .

. - , .

. - , . , ( ) , , .

. , . , , . , .

. 25 dbms? , . , , -, , ..

0

Source: https://habr.com/ru/post/1546901/


All Articles