MoT3rror / egginc-coop-tracker

0 stars 1 forks source link

Improve performance of php<->js communication #28

Closed ayavilevich closed 3 years ago

ayavilevich commented 3 years ago

This communication is used to access the EI API.

Relevant files: js/egg-inc.js app/Api/EggInc.php

Currently every request is sync and invokes the node from php via a shell execution. So web requests seem to be in series and not parallel, plus there is overhead of process invokation.

Perhaps the best solution would be to make the EI API calls in PHP.

protobuf also has PHP libs: https://developers.google.com/protocol-buffers/docs/reference/php-generated https://github.com/protobuf-php/protobuf

Can even do a "stale ok" caching strategy where if data for the user exists it is returned and then an async call is made to refresh the data in cache for next time.

However, for now we are going to do a hybrid solution but one that is parallel and has less overhead.

First, make a node webserver that can make the protobuf EI API requests and return json. It will be called by PHP over http, locally, without doing shell executions. Second, have a method in the new web server that can fetch several user infos at once. Later use in PHP in an optimized manner.

ayavilevich commented 3 years ago

@MoT3rror I have complete the new wrapper. Please take a look and give it a try. LMK if it works better.

https://github.com/MoT3rror/egginc-coop-tracker/tree/feature/interop-performance-boost

For now getPlayerInfos returns an array of individual getPlayerInfo responses (with payload.data schema). This can be changed if you prefer. For example, if it helps, can change it to an object where the id is the key and payload.data is the value.

ayavilevich commented 3 years ago

related to PR: https://github.com/MoT3rror/egginc-coop-tracker/pull/30