> On 4 Jun 2019, at 12:11, naidile.pn <naidilepn@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@gmail.com <mailto:naidilepn@gmail.com>> wrote:
> Thanks a lot!
>
> On Mon, Jun 3, 2019 at 11:45 PM Dmitry Volyntsev <xeioex@nginx.com <mailto:xeioex@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).
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel