Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to generate new requests/responses on duplicate start() #622

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

n0nag0n
Copy link
Collaborator

@n0nag0n n0nag0n commented Feb 14, 2025

This is hopefully to allow for easier integration with platforms like swoole, workerman, etc.

@@ -175,15 +175,20 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(

public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{
$this->expectOutputString(<<<'html'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just some fixes to tests on a windows computer

@@ -378,15 +378,20 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(

public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{
$this->expectOutputString(<<<'html'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just some fixes to tests on a windows computer

@joanhey
Copy link
Contributor

joanhey commented Feb 14, 2025

Still don't work, but work better.

Now if you go to: json, db, fortunes the response change correctly, but if you return the second time after change the URL return a 404.
After that 404, all the request are a 404 response.

Perhaps it's a problem in the dispatcher (need renew anything) and why later show always 404 ?

PD: if the first url is a 404, later all request return 404. Perhaps need to change anything in the dispatcher or router after a 404.
So we can continue to find the problem.

@joanhey
Copy link
Contributor

joanhey commented Feb 14, 2025

How to disable the headers, especially the Content-Lenght ??
The Content-Lenght is automatic in PHP. And if use gzip, brotli, ... the length is different.

@joanhey
Copy link
Contributor

joanhey commented Feb 14, 2025

After check a bit the code, we can create tests for async.

https://github.com/flightphp/core/blob/master/tests/EngineTest.php

We can test more than 1 url (routes) in the same test method, to check if all work correctly. It isn't necessary Adapterman for that.

Only without setUP() is possible to test it, with all the test methods !!

@n0nag0n
Copy link
Collaborator Author

n0nag0n commented Feb 16, 2025

Still don't work, but work better.

Now if you go to: json, db, fortunes the response change correctly, but if you return the second time after change the URL return a 404. After that 404, all the request are a 404 response.

Perhaps it's a problem in the dispatcher (need renew anything) and why later show always 404 ?

PD: if the first url is a 404, later all request return 404. Perhaps need to change anything in the dispatcher or router after a 404. So we can continue to find the problem.

It's weird cause in the unit test, it should in theory run into the same problem because start is called twice. Maybe there's something else that needs to be considered. I'll probably build another unit test to see if I can replicate.

@n0nag0n
Copy link
Collaborator Author

n0nag0n commented Feb 16, 2025

How to disable the headers, especially the Content-Lenght ?? The Content-Lenght is automatic in PHP. And if use gzip, brotli, ... the length is different.

This behavior can be shut off https://docs.flightphp.com/learn/configuration

@n0nag0n
Copy link
Collaborator Author

n0nag0n commented Feb 21, 2025

@joanhey Unit testing is my favorite thing! I was able to replicate the behavior as you can see in the FlightAsyncTest->testMultipleStartsMultipleRoutes() method. The issue was the router needed to be reset to the first position.

You can shut off the content length by setting Flight to be $app->set('flight.content_length', false); or Flight::set('flight.content_length', false); depending on how you have it setup.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

If you know that the problem is the router. You need to fix it !!

PD: now you reset() the Router, but exist more efficient ways.
The framework don't need to parse again all the routes with each Request.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

Flight::set('flight.content_length', false);

Need to be the default.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

Register the Request and Response, it's better to do it in the start only and not in the init().

For each request, always it's necessary a new Request and Response.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

Now it's working with Adapterman:

flight-workerman: Installing dependencies from lock file (including require-dev)                                                                               
flight-workerman: Package operations: 3 installs, 0 updates, 0 removals
flight-workerman:   - Downloading flightphp/core (dev-new-request-object 7dd52c9)                                                                              
flight-workerman:   - Downloading workerman/workerman (v4.2.1)                                                                                                 
flight-workerman:   - Downloading joanhey/adapterman (0.7.0)                                                                                                   
flight-workerman:     0 [>---------------------------]    0 [->--------------------------]                                                                     
flight-workerman:   - Installing flightphp/core (dev-new-request-object 7dd52c9): Extracting archive                                                           
flight-workerman:   - Installing workerman/workerman (v4.2.1): Extracting archive                                                                              
flight-workerman:   - Installing joanhey/adapterman (0.7.0): Extracting archive                                                                                
flight-workerman:  0/3 [>---------------------------]   0%                                                                                                     
flight-workerman:  3/3 [============================] 100%                                                                                                     
flight-workerman: 3 package suggestions were added by new dependencies, use `composer suggest` to see details.
flight-workerman: Generating autoload files                                                                                                                    
flight-workerman: 2 packages you are using are looking for funding.                                                                                            
flight-workerman: Use the `composer fund` command to find out more!                                                                                            
flight-workerman: No security vulnerability advisories found.
flight-workerman:  ---> Removed intermediate container 8378ba760532                                                                                            
flight-workerman:  ---> cd852e31052d
flight-workerman: Step 14/18 : RUN composer install --optimize-autoloader --classmap-authoritative --no-dev
flight-workerman:  ---> Running in 1e4c5d639729
flight-workerman: Installing dependencies from lock file
flight-workerman: Verifying lock file contents can be installed on current platform.                                                                           
flight-workerman: Nothing to install, update or remove                                                                                                         
flight-workerman: Generating optimized autoload files                                                                                                          
flight-workerman: 2 packages you are using are looking for funding.                                                                                            
flight-workerman: Use the `composer fund` command to find out more!                                                                                            
flight-workerman:  ---> Removed intermediate container 1e4c5d639729
flight-workerman:  ---> 2bf3b255e49c
flight-workerman: Step 15/18 : RUN sed -i "s|Flight::start() ;|//Flight::start() ;|g" index.php
flight-workerman:  ---> Running in e76aa27e8d47
flight-workerman:  ---> Removed intermediate container e76aa27e8d47
flight-workerman:  ---> 6c8e6411f9d4
flight-workerman: Step 16/18 : RUN chmod -R 777 /flight
flight-workerman:  ---> Running in eff8e1499bf9
flight-workerman:  ---> Removed intermediate container eff8e1499bf9
flight-workerman:  ---> 3da86b42d8a5
flight-workerman: Step 17/18 : EXPOSE 8080
flight-workerman:  ---> Running in 8d0eced1e6db
flight-workerman:  ---> Removed intermediate container 8d0eced1e6db
flight-workerman:  ---> 195b756b8009
flight-workerman: Step 18/18 : CMD php -c deploy/conf/cli-php.ini     server.php start
flight-workerman:  ---> Running in 4c73ebffce18
flight-workerman:  ---> Removed intermediate container 4c73ebffce18
flight-workerman:  ---> 25e13ce63e82
flight-workerman: [Warning] One or more build-args [BENCHMARK_ENV TFB_TEST_DATABASE TFB_TEST_NAME] were not consumed
flight-workerman: Successfully built 25e13ce63e82
flight-workerman: Successfully tagged techempower/tfb.test.flight-workerman:latest
flight-workerman: Build time: 2m 44s
Running docker container with cpu set: 
flight-workerman: Adapterman/0.7.0 (Workerman/4.2.1) OK
flight-workerman: Workerman[server.php] start in DEBUG mode
flight-workerman: ------------------------------------------- WORKERMAN --------------------------------------------
flight-workerman: Workerman version:4.2.1          PHP version:8.4.4           Event-Loop:\Workerman\Events\Event
flight-workerman: -------------------------------------------- WORKERS ---------------------------------------------
flight-workerman: proto   user            worker               listen                 processes    status           
flight-workerman: tcp     root            AdapterMan-Flight    http://0.0.0.0:8080    32            [OK]            
flight-workerman: --------------------------------------------------------------------------------------------------
flight-workerman: Press Ctrl+C to stop. Start success.
flight-workerman: Verifying framework URLs
--------------------------------------------------------------------------------
VERIFYING DB                                                                                                                                                   
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/db:                                                                                                                       
Accessing URL http://tfb-server:8080/db: 
--------------------------------------------------------------------------------
VERIFYING QUERY COUNT FOR http://tfb-server:8080/db                                                                                                            
--------------------------------------------------------------------------------
New configuration template added to /home/ubuntu/.siege                                                                                                        
Run siege -C to view the current settings in that file
** SIEGE 4.0.7
** Preparing 512 concurrent users for battle.
The server is now under siege...
Transactions:                    512 hits
Availability:                 100.00 %
Elapsed time:                   0.34 secs
Data transferred:               0.02 MB
Response time:                  0.24 secs
Transaction rate:            1505.88 trans/sec
Throughput:                     0.04 MB/sec
Concurrency:                  358.24
Successful transactions:         512
Failed transactions:               0
Longest transaction:            0.32
Shortest transaction:           0.02
 

   PASS for http://tfb-server:8080/db
     Executed queries: 520/512
   PASS for http://tfb-server:8080/db
     Rows read: 511/512
--------------------------------------------------------------------------------
VERIFYING JSON                                                                                                                                                 
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/json:                                                                                                                     
Accessing URL http://tfb-server:8080/json: 
   PASS for http://tfb-server:8080/json
--------------------------------------------------------------------------------
VERIFYING QUERY                                                                                                                                                
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/db-multiple?queries=2:                                                                                                    
Accessing URL http://tfb-server:8080/db-multiple?queries=2: 
Accessing URL http://tfb-server:8080/db-multiple?queries=0: 
Accessing URL http://tfb-server:8080/db-multiple?queries=0: 
Accessing URL http://tfb-server:8080/db-multiple?queries=foo: 
Accessing URL http://tfb-server:8080/db-multiple?queries=foo: 
Accessing URL http://tfb-server:8080/db-multiple?queries=501: 
Accessing URL http://tfb-server:8080/db-multiple?queries=501: 
Accessing URL http://tfb-server:8080/db-multiple?queries=: 
Accessing URL http://tfb-server:8080/db-multiple?queries=: 
--------------------------------------------------------------------------------
VERIFYING QUERY COUNT FOR http://tfb-server:8080/db-multiple?queries=20                                                                                        
--------------------------------------------------------------------------------
** SIEGE 4.0.7                                                                                                                                                 
** Preparing 512 concurrent users for battle.
The server is now under siege...
Transactions:                    512 hits
Availability:                 100.00 %
Elapsed time:                   0.55 secs
Data transferred:               0.31 MB
Response time:                  0.16 secs
Transaction rate:             930.91 trans/sec
Throughput:                     0.57 MB/sec
Concurrency:                  147.71
Successful transactions:         512
Failed transactions:               0
Longest transaction:            0.45
Shortest transaction:           0.00
 

   PASS for http://tfb-server:8080/db-multiple?queries=20
     Executed queries: 10395/10240
   PASS for http://tfb-server:8080/db-multiple?queries=20
     Rows read: 10240/10240
--------------------------------------------------------------------------------
VERIFYING UPDATE                                                                                                                                               
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/updates?queries=2:                                                                                                        
Accessing URL http://tfb-server:8080/updates?queries=2: 
Accessing URL http://tfb-server:8080/updates?queries=0: 
Accessing URL http://tfb-server:8080/updates?queries=0: 
Accessing URL http://tfb-server:8080/updates?queries=foo: 
Accessing URL http://tfb-server:8080/updates?queries=foo: 
Accessing URL http://tfb-server:8080/updates?queries=501: 
Accessing URL http://tfb-server:8080/updates?queries=501: 
Accessing URL http://tfb-server:8080/updates?queries=: 
Accessing URL http://tfb-server:8080/updates?queries=: 
--------------------------------------------------------------------------------
VERIFYING QUERY COUNT FOR http://tfb-server:8080/updates?queries=20                                                                                            
--------------------------------------------------------------------------------
** SIEGE 4.0.7                                                                                                                                                 
** Preparing 512 concurrent users for battle.
The server is now under siege...
Transactions:                    512 hits
Availability:                 100.00 %
Elapsed time:                   2.05 secs
Data transferred:               0.31 MB
Response time:                  1.07 secs
Transaction rate:             249.76 trans/sec
Throughput:                     0.15 MB/sec
Concurrency:                  268.06
Successful transactions:         512
Failed transactions:               0
Longest transaction:            1.98
Shortest transaction:           0.02
 

   PASS for http://tfb-server:8080/updates?queries=20
     Executed queries: 20788/20480
   PASS for http://tfb-server:8080/updates?queries=20
     Rows read: 10241/10240
   PASS for http://tfb-server:8080/updates?queries=20
     Rows updated: 10238/10240
--------------------------------------------------------------------------------
VERIFYING FORTUNE                                                                                                                                              
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/fortunes:                                                                                                                 
Accessing URL http://tfb-server:8080/fortunes: 
--------------------------------------------------------------------------------
VERIFYING QUERY COUNT FOR http://tfb-server:8080/fortunes                                                                                                      
--------------------------------------------------------------------------------
** SIEGE 4.0.7                                                                                                                                                 
** Preparing 512 concurrent users for battle.
The server is now under siege...
Transactions:                    512 hits
Availability:                 100.00 %
Elapsed time:                   0.57 secs
Data transferred:               1.07 MB
Response time:                  0.33 secs
Transaction rate:             898.25 trans/sec
Throughput:                     1.87 MB/sec
Concurrency:                  296.65
Successful transactions:         512
Failed transactions:               0
Longest transaction:            0.53
Shortest transaction:           0.01
 

   PASS for http://tfb-server:8080/fortunes
     Executed queries: 521/512
   PASS for http://tfb-server:8080/fortunes
     Rows read: 6143/6144
--------------------------------------------------------------------------------
VERIFYING PLAINTEXT                                                                                                                                            
--------------------------------------------------------------------------------
Accessing URL http://tfb-server:8080/plaintext:                                                                                                                
Accessing URL http://tfb-server:8080/plaintext: 
   PASS for http://tfb-server:8080/plaintext
Auditing /FrameworkBenchmarks/frameworks/PHP/flight:
No problems to report
wrk: Build time: 1s
techempower/mysql:latest: Build time: 1s
flight-workerman: Build time: 2m 44s
flight-workerman: Time starting database: 13s
flight-workerman: Time until accepting requests: 0s
flight-workerman: Verify time: 51s
flight-workerman: Total test time: 3m 56s
tfb: Total time building so far: 2m 46s
tfb: Total time verifying so far: 51s
tfb: Total execution time so far: 3m 59s
================================================================================
Verification Summary                                                                                                                                           
--------------------------------------------------------------------------------
| flight-workerman                                                                                                                                             
|       db            : PASS                                                                                                                                   
|       json          : PASS                                                                                                                                   
|       query         : PASS                                                                                                                                   
|       update        : PASS                                                                                                                                   
|       fortune       : PASS                                                                                                                                   
|       plaintext     : PASS                                                                                                                                   
================================================================================                                                                               
                                                                                                                                                               
Results are saved in /FrameworkBenchmarks/results/20250221170853

@n0nag0n n0nag0n merged commit b6ab088 into master Feb 21, 2025
6 checks passed
@n0nag0n n0nag0n deleted the new-request-object branch February 21, 2025 17:42
@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

Another detail, remember that Adapterman need minimum PHP 8.0, if you add to the docs.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

When you create a new version, I'll add it to the Techempower Benchmark.

@n0nag0n
Copy link
Collaborator Author

n0nag0n commented Feb 21, 2025

I created version 3.14.0 and merged this and a few other things into it.

https://github.com/flightphp/core/releases/tag/v3.14.0

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

With the last PRs merged, also the normal Flight will be faster.

@joanhey
Copy link
Contributor

joanhey commented Feb 21, 2025

Added to Techempower benchmark

TechEmpower/FrameworkBenchmarks#9598

PD: check the changes to use it with Adapterman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants