Project

General

Profile

Bug #14490

MJIT slows down Rails applications

Added by sam.saffron (Sam Saffron) 4 months ago. Updated 4 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:85625]

Description

This was reported earlier but I would like to add some test methodology here: (tested using Discourse)

What I tested

  1. Run ruby script/bench.rb to warm up profiling database

  2. Run RUBYOPT='--jit --jit-verbose=1 --jit-max-cache=10000' RAILS_ENV=profile bin/puma -e production

    1. Increasing the cache size is an attempt to get higher hit rates
  3. WAIT 5-15 or so minutes for all jitting to stop so we have no cross talk

  4. Run ab -n 100 http://localhost:9292/

  5. Wait for all new jitting to finish

  6. Run ab -n 100 http://localhost:9292/

The absolute best I get is around 61ms median for the test. With MJIT

This is MJIT results!

Percentage of the requests served within a certain time (ms)
  50%     61
  66%     63
  75%     70
  80%     71
  90%     73
  95%     83
  98%    106
  99%    109
 100%    109 (longest request)

Compared to w/o MJIT which is:

Percentage of the requests served within a certain time (ms)
  50%     47
  66%     48
  75%     50
  80%     51
  90%     60
  95%     62
  98%     75
  99%     77
 100%     77 (longest request)

Theory on why this happens

I suspect this is happening cause we are introducing new overhead to every single method dispatch (counting for mjit, and hash lookup and so on). This overhead adds up.

History

#1 Updated by sam.saffron (Sam Saffron) 4 months ago

  • Description updated (diff)

#2 [ruby-core:85627] Updated by k0kubun (Takashi Kokubun) 4 months ago

  • Assignee set to k0kubun (Takashi Kokubun)

Yes, I recognize this problem and will investigate the cause for sure. I don't know a clear cause for this yet.

I suspect this is happening cause we are introducing new overhead to every single method dispatch (counting for mjit, and hash lookup and so on). This overhead adds up.

My understanding of new overheads: JIT enqueue on 5 total calls, total calls count up (sometimes it happens twice for now), JIT-ed C function call instead continueing in the same VM, and additional VM invocation for not JIT-ed methods or JIT cancel. Some of those overheads might grow in Rails. I need investigation.

I'm not sure what's hash lookup.

#3 [ruby-core:85629] Updated by k0kubun (Takashi Kokubun) 4 months ago

This was reported earlier but I would like to add some test methodology here: (tested using Discourse)

Ah, somehow I didn't read this part. Thank you for sharing! I'm using the similar way.

Also available in: Atom PDF