<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 4 Jun 2019, at 12:11, naidile.pn <<a href="mailto:naidilepn@gmail.com" class="">naidilepn@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Dmitry,<div class=""><br class=""></div><div class="">Could you please help me in understanding the difference between js_content and js_preread with usecases.</div></div></div></blockquote><div><br class=""></div><div>js_content is a directive of http njs module (<a href="http://nginx.org/en/docs/http/ngx_http_js_module.html#js_content" class="">http://nginx.org/en/docs/http/ngx_http_js_module.html#js_content</a>). It sets an njs function as a location content handler (The requests are processed in phases, see <a href="http://nginx.org/en/docs/dev/development_guide.html#http_phases" class="">http://nginx.org/en/docs/dev/development_guide.html#http_phases</a> NGX_HTTP_CONTENT_PHASE). </div><div><br class=""></div><div>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).</div><div><br class=""></div><div>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).</div><div><br class=""></div><div>js_preread is a directive of stream njs module, it works on tcp level (<a href="http://nginx.org/en/docs/stream/ngx_stream_js_module.html#js_preread" class="">http://nginx.org/en/docs/stream/ngx_stream_js_module.html#js_preread</a>). The function is invoked once per each tcp connection. To wait for more data asynchronously you have </div><div>s.on(‘upload’, function (data, flags) {…}) and s.done([code]) to move to the next phase.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Regards,</div><div class="">Naidile</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 3, 2019 at 11:49 PM <a href="http://naidile.pn/" class="">naidile.pn</a> <<a href="mailto:naidilepn@gmail.com" class="">naidilepn@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Thanks a lot!</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 3, 2019 at 11:45 PM Dmitry Volyntsev <<a href="mailto:xeioex@nginx.com" target="_blank" class="">xeioex@nginx.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br class="">
<br class="">
On 03.06.2019 21:07, <a href="http://naidile.pn/" rel="noreferrer" target="_blank" class="">naidile.pn</a> wrote:<br class="">
> Which one has more performance - Lua or NJS ?<br class="">
<br class="">
<br class="">
In benchmarks I did, I saw no big differences (njs was slightly better <br class="">
(< 5%)). Because, in real case scenarios not the interpreter is the <br class="">
bottleneck (If you do not do too much math heavy lifting).<br class="">
</blockquote></div>
</blockquote></div>
</div></blockquote></div><br class=""></body></html>