Open GA9BR1 opened 1 month ago
It has worked in the past. Give me a few days to take a look at the configuration. On the road right now.
When using multiple threads the Agoo::Server.start() returns. Previously I thought the app just exited after that. That does not seem to be the case now. The intent was to allow the application to do other actions after starting but since your app doesn't seem to need do anything other than wait, a simple sleep loop like the following should be enough:
while true
sleep(1)
end
I think what you were seeing was the main thread exiting and then each thread would block until the last which crashed. I'll look at detecting the main thread exiting and then killing the children. I am a bit surprised that is needed but it certainly seems like it is now.
Latest release now exits if no wait loop is present. An example was also added.
Awesome thank you :D
I tried to run one load test in my app, and i got this error now:
api01 | double free or corruption (top)
api01 | /app/payment.rb:75: [BUG] Segmentation fault at 0x0000000000000000
api01 | ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [x86_64-linux]
api01 |
api01 | -- Control frame information -----------------------------------------------
api01 | c:0006 p:---- s:0030 e:000029 CFUNC :exec_params
api01 | c:0005 p:0018 s:0024 e:000023 METHOD /app/payment.rb:75
api01 | c:0004 p:0016 s:0019 e:000018 METHOD /app/payment.rb:18
api01 | c:0003 p:0014 s:0015 e:000014 METHOD server.rb:32
api01 | c:0002 p:0033 s:0008 e:000007 METHOD server.rb:22 [FINISH]
api01 | c:0001 p:---- s:0003 e:000002 DUMMY [FINISH]
api01 |
api01 | -- Ruby level backtrace information ----------------------------------------
api01 | server.rb:22:in `call'
api01 | server.rb:32:in `handle_payment'
api01 | /app/payment.rb:18:in `call'
api01 | /app/payment.rb:75:in `debit_amount'
api01 | /app/payment.rb:75:in `exec_params'
api01 |
api01 | -- Threading information ---------------------------------------------------
api01 | Total ractor count: 1
api01 | Ruby thread count for this ractor: 5
api01 |
api01 | -- Machine register context ------------------------------------------------
api01 | RIP: 0x00007cd2229b950f RBP: 0x00007cd204dcc6c0 RSP: 0x00007cd204dcb040
api01 | RAX: 0x0000000000000000 RBX: 0x00007cd222b66e70 RCX: 0x00007cd222a1de2c
api01 | RDX: 0x0000000000000000 RDI: 0x0000000000000001 RSI: 0x0000000000000011
api01 | R8: 0x0000000000000000 R9: 0x0000000000000000 R10: 0x0000000000000008
api01 | R11: 0x0000000000000246 R12: 0x00007cd204dcb120 R13: 0x00007cd222d31000
api01 | R14: 0x0000000000000001 R15: 0x0000000000000001 EFL: 0x0000000000010246
api01 |
api01 | -- C level backtrace information -------------------------------------------
Can you give me a test to help narrow it down?
Sure. In this repository you will have the gattling test that I'm using: https://github.com/zanfranceschi/rinha-de-backend-2024-q1. And in this one it's mine app https://github.com/GA9BR1/rinha-de-backend-2024-q1 the only differences between this one and my local one are that the app in the repository is not using multi-thread, the agoo version is different on the gemfile and the limitations on the docker-compose that i have removed in my local to test if the problem could be it.
That will take a bit to get set up. If you are willing go into the Makefile and define MEM_DEBUG. That will turn on memory debugging. It should catch the double free and tell us where it is happening.
Where can i found this Makefile?
Sounds like you might need a few directions so I'll describe how to try out a new branch and also update the Makefile.
ruby extconf.rb
CFLAGS
and add -DMEM_DEBUG
make
which will build the bundle.ruby -Iext -Ilib
but use what ever that needed from where you run.gem build agoo.gemspec
followed by an install of gem install agoo-xxx
where xxx is what ever version is of the gem file.
I was looking at the docs and I found that Server.init has a parameter thread_count, I was using it default and then I tried to go multi-threaded. I started the server with 4, 3 and 2 for thread_count but when I do a request to the server it just doesn't respond me. I was thinking that my code is the problem but I remove everything to test and just leaved a simple handler and it still with the same behavior(when it was single threaded it was working fine). I don't know if I'm missing something, if it's needed to do something extra, or if it's just a bug. An important detail is that in this log I tried to send 4 requests to the server and in the fourth one the server crashes. If I do with 3 threads it will be 3 requests and if it's with 2 threads it will be 2.
I startup the server with ruby server.rb Ruby 3.3.3 Ubuntu 22.04.4 LTS