-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverview.html
37 lines (35 loc) · 4.66 KB
/
overview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<html>
<head>
<title>Overview of JavaPengine</title>
</head>
<body>
<h1>JavaPengines</h1>
<p>JavaPengines is a client library for Torbjörn Lager's <b>Pengines</b> distributed computing library for
<b>SWI-Prolog</b>
<h2>Installation</h2>
<p>This library, which is available as a jar from Maven Central with groupID com.simularity and ArtifactID com.simularity.os.javapengine, or as sources at <a href="http://www.github.com/Simularity/Javapengine/">Github</a>.</p>
<p><b>JavaPengine</b> requires <b>javax.json</b></p>
<h2>Understanding JavaPengine</h2>
<p>JavaPengine is a thin wrapper around <a href="http://pengines.swi-prolog.org/docs/index.html">Pengines</a>, and so best use requires knowledge of the Pengines system, although only minimal understanding of pengines or of Prolog is sufficient to make basic queries</p>
<p>Unlike imperative programs, in Prolog one constructs a "knowledgebase" of rules about a world, and then asks the system to find proofs of propositions, called queries. So there are two parts to a Prolog program - the rules, and the query.</p>
<p>SWI-Prolog is probably the most widely used implementation of Prolog, particularly suitable for large <i>real world</i> projects.</p>
<p>Pengines extends SWI-Prolog to provide a distributed computing environment. Pengines exposes an HTTP based protocol that allows a remote system to submit queries and even alter the knowledgebase.<p>
<p>This is not unlike how web servers supply Javascript to the browser to execute, with the client in role of the server and the pengine server in role of the web browser.</p>
<p>Obviously doing this in an unconstrained way would be a huge security issue. So pengines executes the remote-supplied code in a sandbox.</p>
<p>Each created pengine creates, effectively, it's own Prolog sub-VM. Different pengine slaves see different knowledgebases. The pengine's knowledgebase is a combination of what the server chooses to expose, and what the client supplies. The server supplied part includes the safe parts of the standard Prolog libraries. For a complete explanation of this process, watch <a href="https://www.youtube.com/watch?v=JmOHV5IlPyU">my video from Strange Loop</a></p>
<p>This provides lots of benefits. The remote client has a full, Turing complete language available for writing queries. Need some complex natural language scoring function computed to decide whether you need that row of data? Do it on the server.</p>
<p>The remote client can also store data on the server between invocations. Need to hang onto an intermediate stage query? Leave it on the server. Need to do graph traversal looking things? Do it on the server. Have a really complicated query you don't want to transmit for each query? Leave the code for it on the server.</p>
<h2>Life Cycle</h2>
<p>A slave pengine is created, used for zero or more queries, and then destroyed, either explicitly or by timing out.</p>
<p>A common, but not universal, pattern is to create a pengine, query it once, then destroy it. So JavaPengine supports this by allowing you to just make a query and repeatedly ask for the answers.</p>
<p>Prolog queries may return a single answer, but they can also fail (return no answer) or return many answers. This is fundamental to the SLD resolution mechanism at the core of Prolog. But often we know that queries will return a single answer, and we call this being <i>deterministic</i> or <i>det</i>. Those other queries are <i>nondeterministic</i>, or <i>nondet</i>.</p>
<p>JavaPengine has special support for making deterministic queries, and for making a single query and then destroying the pengine. This support is not only for convenience, but for efficiency.</p>
<p>In it's most basic use, the pengines protocol requires one HTTP request to create the pengine, one to initiate a query and get the first answer, one for each answer thereafter, and one to destroy the pengine.</p>
<p>But the pengines protocol allows the client to send the first query with the create message. This saves an HTTP round trip. The protocol also contains a flag that says 'destroy this pengine at the end of the first query'. This saves another round trip. For a pengine that is used for a single deterministic query, this reduces the number of HTTP requests from 3 to 1, a factor of 3 reduction in network traffic.</p>
<p>The <a href="com/simularity/os/javapengine/PengineFactory.html#getQuery-com.simularity.os.javapengine.PengineOptions-">getQuery</a> and <a href="com/simularity/os/javapengine/PengineFactory.html#getProof-java.lang.String-">getProof</a> methods use these optimizations internally. Their use when appropriate can reduce network traffic.</p>
<h2>API</h2>
<p>TODO will write this when it's more ready</p>
<h2>Templates</h2>
<p>TODO</p>
</body>
</html>