You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2020/05/28 01:56:57 UTC

[incubator-nlpcraft-website] branch master updated: Fix for NLPCRAFT-65.

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ae1932  Fix for NLPCRAFT-65.
2ae1932 is described below

commit 2ae19323c51ae22a387ac2999b5afa9f424a2298
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Wed May 27 18:56:46 2020 -0700

    Fix for NLPCRAFT-65.
---
 _scss/misc.scss           |   4 ++
 images/emb_probe1.png     | Bin 0 -> 90626 bytes
 images/emb_probe2.png     | Bin 0 -> 112865 bytes
 tools/embedded_probe.html | 121 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/test_framework.html |   2 +-
 5 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/_scss/misc.scss b/_scss/misc.scss
index c5fceb5..6327fc2 100644
--- a/_scss/misc.scss
+++ b/_scss/misc.scss
@@ -388,5 +388,9 @@ code {
     }
 }
 
+.img-fluid {
+    max-width: 800px !important;
+}
+
 
 
diff --git a/images/emb_probe1.png b/images/emb_probe1.png
new file mode 100644
index 0000000..b2b40a4
Binary files /dev/null and b/images/emb_probe1.png differ
diff --git a/images/emb_probe2.png b/images/emb_probe2.png
new file mode 100644
index 0000000..2d2cd6b
Binary files /dev/null and b/images/emb_probe2.png differ
diff --git a/tools/embedded_probe.html b/tools/embedded_probe.html
index 7a61a81..190de11 100644
--- a/tools/embedded_probe.html
+++ b/tools/embedded_probe.html
@@ -24,12 +24,133 @@ id: embedded_probe
 <div class="col-md-8 second-column">
     <section id="overview">
         <h2 class="section-title">Overview</h2>
+        <p>
+            Embedded probe allows to run data probe in the same JVM process as JVM-based client application.
+        </p>
+        <p>
+            Typically, data probes are launched in their own independent JVMs. However, when a client application is
+            itself a JVM-based process, it is sometimes preferable for performance reasons to to host
+            a data model - and hence the data probe - in the same "client" JVM.
+        </p>
+        <p>
+            In a standard processing flow, when data probe (with its deployed data models) is hosted in its own independent JVM,
+            the request from
+            the client application takes 4 network hops to go server, then to the data probe and back to the client application (see fig 1. below):
+        </p>
+        <figure>
+            <img class="img-fluid" src="/images/emb_probe1.png" alt="">
+            <figcaption><b>Fig 1.</b> Standard Processing Flow</figcaption>
+        </figure>
+        <p>
+            When performing model unit testing or when client "application" can be combined with the data probe in a single JVM, the
+            embedded probe mode provides significant performance advantage. Using embedded probe you can reduce number
+            of network hops to 2 in a similar scenario (see fig 2.):
+        </p>
+        <figure>
+            <img class="img-fluid" src="/images/emb_probe2.png" alt="">
+            <figcaption><b>Fig 2.</b> Embedded Processing Flow</figcaption>
+        </figure>
+    </section>
+    <section id="usage">
+        <h2 class="section-title">Usage</h2>
+        <p>
+            Embedded probe support consists of the following types in <code>org.apache.nlpcraft.probe.embedded</code> package:
+        </p>
+        <ul>
+            <li>
+                <a
+                    target="javadoc"
+                    href="https://javadoc.io/static/org.apache.nlpcraft/nlpcraft/0.5.0/org/apache/nlpcraft/probe/embedded/NCEmbeddedProbe.html">
+                    NCEmbeddedProbe
+                </a> - Embedded probe main class.
+            </li>
+            <li>
+                <a
+                    target="javadoc"
+                    href="https://javadoc.io/static/org.apache.nlpcraft/nlpcraft/0.5.0/org/apache/nlpcraft/probe/embedded/NCEmbeddedResult.html">
+                    NCEmbeddedResult
+                </a> - Processing result container since result is delivered as a local JVM call.
+            </li>
+        </ul>
+        <p>
+            Here's an code snippet from <a target="javadoc" href="https://github.com/apache/incubator-nlpcraft/blob/master/src/main/scala/org/apache/nlpcraft/examples/alarm/AlarmTest.java">Alarm Clock</a>
+            example illustrating the usage embedded probe together with test framework together and JUnit 5:
+        </p>
+        <pre class="brush: java, highlight: [6, 18]">
+public class AlarmTest {
+    private NCTestClient cli;
+
+    &#64;BeforeEach
+    void setUp() throws NCException, IOException {
+        NCEmbeddedProbe.start(AlarmModel.class);
+
+        cli = new NCTestClientBuilder().newBuilder().build();
+
+        cli.open("nlpcraft.alarm.ex");
+    }
+
+    &#64;AfterEach
+    void tearDown() throws NCException, IOException {
+        if (cli != null)
+            cli.close();
+
+        NCEmbeddedProbe.stop();
+    }
+
+    &#64;Test
+    public void test() throws NCException, IOException {
+        // Should be passed.
+        assertTrue(cli.ask("Ping me in 3 minutes").isOk());
+        assertTrue(cli.ask("Buzz me in an hour and 15mins").isOk());
+        assertTrue(cli.ask("Set my alarm for 30s").isOk());
+    }
+}
+        </pre>
+        <p>
+            Notes:
+        </p>
+        <ul>
+            <li>
+                Lines 6 and 18 show the embedded data probe start and stop as it's used in the unit tests.
+            </li>
+        </ul>
+        <p>
+            It's important to note that there are number of inherent limitations associated with embedded probe:
+        </p>
+        <ul>
+            <li>
+                Embedded probe is only available for JVM-based applications (and can be used with any JVM languages).
+            </li>
+            <li>
+                There can be only one embedded probe per JVM.
+            </li>
+            <li>
+                Once data probe is stopped and cannot be re-started again in the same JVM.
+            </li>
+            <li>
+                Even though the caller can register local-JVM listener for the query results, these results
+                will still be asynchronously delivered to the REST server in the usual manner so that other clients
+                could fetch these results to maintain internal logging, tracing and metrics. If the client
+                application hosting data model and its probe <i>is the only client</i> for that model it needs to cancel the
+                request on the REST server after receiving a local-JVM callback to release associated
+                resources on the REST server.
+            </li>
+        </ul>
+    </section>
+    <section id="examples">
+        <h2 class="section-title">Examples</h2>
+        <p>
+            All <a target="github" href="https://github.com/apache/incubator-nlpcraft/tree/master/src/main/scala/org/apache/nlpcraft/examples">examples</a>
+            shipped with NLPCraft utilize embedded probes in their unit tests.
+        </p>
     </section>
 </div>
 <div class="col-md-2 third-column">
     <ul class="side-nav">
         <li class="side-nav-title">On This Page</li>
         <li><a href="#overview">Overview</a></li>
+        <li><a href="#usage">Usage</a></li>
+        <li><a href="#examples">Examples</a></li>
         {% include quick-links.html %}
     </ul>
 </div>
diff --git a/tools/test_framework.html b/tools/test_framework.html
index da87a9f..8b393a7 100644
--- a/tools/test_framework.html
+++ b/tools/test_framework.html
@@ -101,7 +101,7 @@ public class AlarmTest {
 }
         </pre>
         <p>
-            Few notes:
+            Notes:
         </p>
         <ul>
             <li>