NJS - API Calls
Dmitry Volyntsev
xeioex at nginx.com
Tue Jun 4 09:31:40 UTC 2019
> On 4 Jun 2019, at 12:11, naidile.pn <naidilepn at gmail.com> wrote:
>
> Hi Dmitry,
>
> Could you please help me in understanding the difference between js_content and js_preread with usecases.
js_content is a directive of http njs module (http://nginx.org/en/docs/http/ngx_http_js_module.html#js_content <http://nginx.org/en/docs/http/ngx_http_js_module.html#js_content>). It sets an njs function as a location content handler (The requests are processed in phases, see http://nginx.org/en/docs/dev/development_guide.html#http_phases <http://nginx.org/en/docs/dev/development_guide.html#http_phases> NGX_HTTP_CONTENT_PHASE).
The function is invoked once per each request. In it you are responsible for generating complete http responses. The NGX_HTTP_CONTENT_PHASE is not finished until you have pending actions (active subrequests or timers).
The only way to make "external http calls” is to make a subrequest to a separate location with proxy_pass directive (here you can use variables to make subrequests to different endpoints).
js_preread is a directive of stream njs module, it works on tcp level (http://nginx.org/en/docs/stream/ngx_stream_js_module.html#js_preread <http://nginx.org/en/docs/stream/ngx_stream_js_module.html#js_preread>). The function is invoked once per each tcp connection. To wait for more data asynchronously you have
s.on(‘upload’, function (data, flags) {…}) and s.done([code]) to move to the next phase.
>
> Regards,
> Naidile
>
> On Mon, Jun 3, 2019 at 11:49 PM naidile.pn <http://naidile.pn/> <naidilepn at gmail.com <mailto:naidilepn at gmail.com>> wrote:
> Thanks a lot!
>
> On Mon, Jun 3, 2019 at 11:45 PM Dmitry Volyntsev <xeioex at nginx.com <mailto:xeioex at nginx.com>> wrote:
>
>
> On 03.06.2019 21:07, naidile.pn <http://naidile.pn/> wrote:
> > Which one has more performance - Lua or NJS ?
>
>
> In benchmarks I did, I saw no big differences (njs was slightly better
> (< 5%)). Because, in real case scenarios not the interpreter is the
> bottleneck (If you do not do too much math heavy lifting).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20190604/0a2be6ba/attachment.html>
More information about the nginx-devel
mailing list