Im trying to solve [this problem](https://forum.openresty.us/d/6596-502-code-under-high-concurrency-pressure-with-simple-logic-in-access-by-lua/6)in which CPU block causes 502.
I've checked my project and found it nearly impossible to apply the ngx.run_worker_thread
solution.
My project's implementation is under single thread assumption, with some optimizations like table pool, worker level in memory cache(I mean for my own codes' logic, not for the file served). The best I can do is to find continual thread safe code segments and put them into ngx.run_worker_thread
.
And the ngx.run_worker_thread
call is not mature enough yet: it's not versioned and packed, also its interface is not polished(we cannot use any ngx_lua
APIs in spawned threads).
My code is OK to be interrupted in some points. I wonder if it yields purposely(like corotinue) in those place, hand over the control flow and wait for proper time to continue, would it solve the problem?
And is there ready-made APIs for me to do this?