@@ -35,34 +35,34 @@ performance, we mean about CPU consumption, Memory usage and Response times.
35
35
Everything matters here, right? At least, everything should matter in terms of
36
36
software economy.
37
37
38
- ** Step 1** - Apache server receives a new request and sends it directly to the
38
+ - ** Step 1** - Apache server receives a new request and sends it directly to the
39
39
app.php file.
40
- ** Step 2** - Symfony kernel boots. That means that, in the better of the cases, the
40
+ - ** Step 2** - Symfony kernel boots. That means that, in the better of the cases, the
41
41
container is cached properly. The Kernel is created * (once again)* , the
42
42
container configuration is loaded from this cache, and a new Request object is
43
43
created with the data received from Apache.
44
- ** Step 3** - The Kernel handles this Request, waiting for a Response.
45
- ** Step 4** - Some framework magic (resolve controller, resolve dispatch some
44
+ - ** Step 3** - The Kernel handles this Request, waiting for a Response.
45
+ - ** Step 4** - Some framework magic (resolve controller, resolve dispatch some
46
46
events...)
47
- ** Step 5** - We call the controller entry point. Remember that we MUST return a
47
+ - ** Step 5** - We call the controller entry point. Remember that we MUST return a
48
48
Response instance (remember that we don't use Views here, so we discard
49
49
returning an array here. Anyway, would be the same).
50
- ** Step 6** - We do our logic. For example, we call a repository to get an array of
50
+ - ** Step 6** - We do our logic. For example, we call a repository to get an array of
51
51
values from Redis.
52
- ** Step 7** - Redis returns an array of values, where the controller return a new
52
+ - ** Step 7** - Redis returns an array of values, where the controller return a new
53
53
Response with these values, where the Kernel, after some extra event dispatches,
54
54
return this Response to Apache, which return the response to the final client.
55
55
56
56
This is one natural Request / Response workflow in one of our applications.
57
57
Fast, isn't it? Let's check in terms of performance.
58
58
59
- ** Step 1** - We must have Apache server installed. By adding Apache as a man in
59
+ - ** Step 1** - We must have Apache server installed. By adding Apache as a man in
60
60
the middle, we spend some time. Even if it's ** 1ms** , we will see later that
61
61
each single ** 1ms** can be so much important here.
62
- ** Step 2** - Symfony kernel is booted every time. Once and again. Every single
62
+ - ** Step 2** - Symfony kernel is booted every time. Once and again. Every single
63
63
request. Let's say... ** 15ms** ? ** 20ms?** Something like that. Let's say
64
64
** 15ms** being SO optimists.
65
- ** Step 7** - Imagine a Redis call as a representation of any external call. This
65
+ - ** Step 7** - Imagine a Redis call as a representation of any external call. This
66
66
could be a redis one (fast one), or an HTTP one, slow one. This action will
67
67
last the time this operation lasts. Let's say ** 50ms** .
68
68
@@ -135,18 +135,18 @@ with some non-blocking clients like the HTTP one or a Redis one.
135
135
136
136
This is the workflow.
137
137
138
- ** Step 1** - ReactPHP receives it's own Request, and creates a Symfony request.
139
- ** Step 2** - The Kernel handles this Request, waiting for a Response.
140
- ** Step 3** - Some framework magic (resolve controller, resolve dispatch some
138
+ - ** Step 1** - ReactPHP receives it's own Request, and creates a Symfony request.
139
+ - ** Step 2** - The Kernel handles this Request, waiting for a Response.
140
+ - ** Step 3** - Some framework magic (resolve controller, resolve dispatch some
141
141
events...)
142
- ** Step 4** - We call the controller entry point. Remember that we MUST return a
142
+ - ** Step 4** - We call the controller entry point. Remember that we MUST return a
143
143
Response instance.
144
- ** Step 5** - We do our logic. For example, we call a repository to get an array
144
+ - ** Step 5** - We do our logic. For example, we call a repository to get an array
145
145
of values from Redis.
146
- ** Step 6** - Redis returns a ** Promise** of values. This promise is returned to
146
+ - ** Step 6** - Redis returns a ** Promise** of values. This promise is returned to
147
147
the controller, and has to be resolved. Once is resolved, returns a Response to
148
148
the Kernel.
149
- ** Step 7** - The Kernel returns the Response to the ReactPHP server, which
149
+ - ** Step 7** - The Kernel returns the Response to the ReactPHP server, which
150
150
creates a new promise with that Response.
151
151
152
152
When checking performance, we see that the I/O, even if it's asynchronous, is
@@ -163,19 +163,19 @@ to the ReactPHP server.
163
163
164
164
Let's check the workflow.
165
165
166
- ** Step 1** - ReactPHP receives it's own Request, and creates a Symfony request.
167
- ** Step 2** - The Kernel handles ** asynchronously** this Request, waiting for a
166
+ - ** Step 1** - ReactPHP receives it's own Request, and creates a Symfony request.
167
+ - ** Step 2** - The Kernel handles ** asynchronously** this Request, waiting for a
168
168
Promise containing a Response.
169
- ** Step 3** - Some framework magic (resolve controller, resolve dispatch some
169
+ - ** Step 3** - Some framework magic (resolve controller, resolve dispatch some
170
170
events...)
171
- ** Step 4** - We call the controller entry point. Now we can return a Promise
171
+ - ** Step 4** - We call the controller entry point. Now we can return a Promise
172
172
instead of a Response instance.
173
- ** Step 5** - We do our logic. For example, we call a repository to get an array
173
+ - ** Step 5** - We do our logic. For example, we call a repository to get an array
174
174
of values from Redis.
175
- ** Step 6** - Redis returns a Promise of values. This promise is returned to
175
+ - ** Step 6** - Redis returns a Promise of values. This promise is returned to
176
176
the controller. No need to resolve anything. Returning the Promise to the
177
177
Kernel.
178
- ** Step 7** - The Kernel returns the Promise to the ReactPHP server. Directly.
178
+ - ** Step 7** - The Kernel returns the Promise to the ReactPHP server. Directly.
179
179
180
180
And checking the performance? Easy. The response will still return in 54ms. We
181
181
can improve this time by improving your networking interface or by adding some
0 commit comments