[keyserver] Add $KEYSERVER_PROFILING_ENABLED to toggle node:cluster
Summary:
The 0x tool mentioned in ENG-5078 does not work with node:cluster. We can modify keyserver.js to launch a single process when KEYSERVER_PROFILING_ENABLED is set. This is what I did in my personal dev environment to get 0x working.
Basically if KEYSERVER_PROFILING_ENABLED is set, we avoid cluster.fork()ing and just "spill" into the else block that would usually only be executed by child processes (cpid == 0). Previous cluster fork()ing logic continues to work as expected when KEYSERVER_PROFILING_ENABLED is unset.
Will users have to set KEYSERVER_PROFILING_ENABLED in their environment manually?
The yarn command for profiling will begin with KEYSERVER=true KEYSERVER_PROFILING_ENABLED=true node... to make this config "invisible" to the dev. As long as they run yarn profile-* things will work as expected.
Depends on D9300
Test Plan:
- Added logging to ensure that conditionals behaved as expected when KEYSERVER_PROFILING_ENABLED is and isn't set.
- Successfully ran profiling session with KEYSERVER=true 0x -o -- node --trace-warnings --loader=./loader.mjs dist/keyserver
Reviewers: ashoat, ginsu, tomek, rohan
Reviewed By: ashoat
Differential Revision: https://phab.comm.dev/D9301