Welcome! Log In Create A New Profile

Advanced

Re: NJS - API Calls

Dmitry Volyntsev
June 04, 2019 05:32AM
> 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
Subject Author Views Posted

NJS - API Calls

naidile.pn 311 June 03, 2019 01:30PM

Re: NJS - API Calls

Dmitry Volyntsev 157 June 03, 2019 01:40PM

Re: NJS - API Calls

naidile.pn 144 June 03, 2019 01:46PM

Re: NJS - API Calls

naidile.pn 227 June 03, 2019 01:48PM

Re: NJS - API Calls

Dmitry Volyntsev 140 June 03, 2019 02:04PM

Re: NJS - API Calls

naidile.pn 149 June 03, 2019 02:10PM

Re: NJS - API Calls

Dmitry Volyntsev 138 June 03, 2019 02:16PM

Re: NJS - API Calls

naidile.pn 141 June 03, 2019 02:22PM

Re: NJS - API Calls

naidile.pn 139 June 04, 2019 05:14AM

Re: NJS - API Calls

Dmitry Volyntsev 153 June 04, 2019 05:32AM

Re: NJS - API Calls

Dmitry Volyntsev 178 June 04, 2019 08:56AM

Re: NJS - API Calls

naidile.pn 184 June 04, 2019 02:46PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 296
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready