Everyone knows that the reason why nginx has great performance is based on its asynchronous and non-blocking nature. Therefore, when developing nginx plug-ins, you must remember to perform certain time-consuming operations in a blocking way when processing network requests. Otherwise it will seriously affect nginx performance...
This question comes up: What if I want to perform some time-consuming operations in the plug-in? For example, querying the database (the database does not support http protocol, there is a special protocol)?
ps: I can open a thread pool and throw these blocking operations into the pool, but is there any way to suspend the current request processing to the event queue of the nginx framework? When changing status is sent in the callback function of a blocking operation, let nginx continue processing the previous request?
grateful
迷茫2017-05-16 17:14:26
Database query is essentially network communication. Essentially, as long as your socket read and write are non-blocking, there will be no problem. This is easier said than done. nginx itself has some reusable mechanisms to implement various non-blocking operations on http. However, communications such as tcp may not be readily available. You have to write it yourself, which I think is more complicated, and it also has to be integrated into nginx.