Using Roadrunner as a server


(Alexander Makarov) #1

As an experiment I have tried to serve demo application using RoadRunner.

Here’s the pull request/branch you can try yourself.

Everything before while ($request = $psr7->acceptRequest()) { runs only once and is kept in memory. That includes whole container state, application, setting error handler etc.

What is executed every request is actual PSR-7 request handling with middleware stack.

I had to adjust the way middleware dispatcher works because of state. Previously it was removing middleware from the stack. Now it is keeping a pointer that could be reset instead.

There is currently a problem with session with more than a single worker. Other than that it seems to work fine. Response times are amazingly good:

INFO[0001] ::1 {59.0ms} 200 GET http://localhost:8080/ <----- warmup
INFO[0002] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0003] ::1 {1.01ms} 200 GET http://localhost:8080/
INFO[0004] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0005] ::1 {4.00ms} 200 GET http://localhost:8080/login
INFO[0012] ::1 {1.052s} 302 POST http://localhost:8080/login <----- password hash computation
INFO[0012] ::1 {1.01ms} 200 GET http://localhost:8080/
INFO[0013] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0014] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0014] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0014] ::1 {1.01ms} 200 GET http://localhost:8080/
INFO[0015] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0015] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0015] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0016] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0016] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0017] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0017] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0018] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0018] ::1 {1.01ms} 200 GET http://localhost:8080/contact
INFO[0018] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0018] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0019] ::1 {1.01ms} 200 GET http://localhost:8080/
INFO[0019] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0020] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0020] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0020] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0021] ::1 {1.00ms} 200 GET http://localhost:8080/
INFO[0068] ::1 {0.99ms} 200 GET http://localhost:8080/
INFO[0069] ::1 {1.00ms} 200 GET http://localhost:8080/contact
INFO[0069] ::1 {2.00ms} 200 GET http://localhost:8080/

(Mariodipatria) #2

Really Interesting! Are you plan to implement it as core component or external package?


(Alexander Makarov) #3
  1. I plan to make sure all core components work in such environment.
  2. Likely there will be packages that provide ready to use extras such as RoadrunnerEmitter from the pull request containing the docs on how to use them.

(Mmta41) #4

Nice job, please do the same for swoole , it is insanely fast!
Yii lost database connection in such environments, it will be nice to have connection pool for database


(Alexander Makarov) #5

Fixed sessions component. Now it works well with multiple workers.


Yii 2.0.27, Debug 2.1.9 and Yii 3 progress