-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphcomp.html
306 lines (278 loc) · 14.4 KB
/
graphcomp.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2021-W52-2 01:13 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DIGRAPH</title>
<meta name="author" content="Inanna" />
<meta name="description" content="A program for defining graphs in clojure." />
<meta name="generator" content="Org Mode" />
<link href="site.css" rel="stylesheet" type="text/css" /><link href="images/website-icon.png" rel="icon" />
</head>
<body>
<div id="preamble" class="status">
<div><a href="index.html"><img alt="A red logo the left half of which is a gear containing a control diagram and the right half is a rose." id="site-logo" src="images/website-logo.png" /></a></div>
</div>
<div id="content" class="content">
<h1 class="title">DIGRAPH</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org49039bd">Introduction</a>
<ul>
<li><a href="#org5812c0b">Filter Nodes</a></li>
<li><a href="#orgf97ad78">Map Nodes</a></li>
<li><a href="#orgd6e5cb2">Collection Nodes</a></li>
<li><a href="#org7ad0899">State Nodes</a></li>
<li><a href="#orge21e17b">I/O Nodes</a></li>
<li><a href="#org3705110">A Note on Cyclic Graphs</a></li>
</ul>
</li>
<li><a href="#org7862557">Plans</a>
<ul>
<li><a href="#orgd3b52ed">GraalVM Compilation</a></li>
<li><a href="#orgf8866c0">Subgraphs</a></li>
<li><a href="#org3e19a70">Live Updates</a></li>
</ul>
</li>
<li><a href="#org0b86369">Changelog</a></li>
<li><a href="#org52c1884">Implementation</a>
<ul>
<li><a href="#org87b0c49">Server Functions</a></li>
<li><a href="#org6e66f40">Macros</a>
<ul>
<li><a href="#org0bb05f9">defgraph</a></li>
<li><a href="#orgc12093e">defdag</a></li>
</ul>
</li>
<li><a href="#orgf7b0e88">Compilation</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org49039bd" class="outline-2">
<h2 id="org49039bd">Introduction</h2>
<div class="outline-text-2" id="text-org49039bd">
<p>
This is a toy project with Kubernetes to implement a series of macros using directed <i>cyclic</i> graphs to produce a deployment for Kubrenetes containers.
</p>
<p>
The graph in essence represents where packets from the containers should be sent and should be received, with the edges of the graph being infinite lists of inputs and outputs from different nodes. Nodes are (mostly) assumed to be stateless <del>classless and moneyless, having thus achieved communism</del> to simplify the operation of the system.
</p>
</div>
<div id="outline-container-org5812c0b" class="outline-3">
<h3 id="org5812c0b">Filter Nodes</h3>
<div class="outline-text-3" id="text-org5812c0b">
<p>
Filter nodes take inputs and then produce outputs should the predicate be true. Should it be nil, they produce no output.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def-filter-node</span> <span style="font-weight: bold; font-style: italic;">name</span> <span style="color: #bbb;">[</span>arg<span style="color: #bbb;">]</span>
<span style="color: #494949;">"Docstring"</span>
<span style="color: #bbb;">()</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf97ad78" class="outline-3">
<h3 id="orgf97ad78">Map Nodes</h3>
<div class="outline-text-3" id="text-orgf97ad78">
<p>
Map nodes simply apply the function that the node represents to all inputs and then returns the outputs to any of the nodes that it is meant to send data to.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def-map-node</span> <span style="font-weight: bold; font-style: italic;">name</span> <span style="color: #bbb;">[</span>arg<span style="color: #bbb;">]</span>
<span style="color: #494949;">"Docstring"</span>
<span style="color: #bbb;">()</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd6e5cb2" class="outline-3">
<h3 id="orgd6e5cb2">Collection Nodes</h3>
<div class="outline-text-3" id="text-orgd6e5cb2">
<p>
Collection nodes work similarly to a reduction function, applying themselves to some list of values and then producing an accumulator.
</p>
<p>
However, unlike a regular reduction function, rather than applying themselves to all elements they have received (since that would be an infinite list and not possible) they apply themselves to a specified number of those elements, or once the elements satisfy a predicate applied to them.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def-col-node</span> <span style="font-weight: bold; font-style: italic;">name</span> <span style="color: #bbb;">[</span>arg<span style="color: #bbb;">]</span> pred-or-num
<span style="color: #494949;">"Docstring"</span>
<span style="color: #bbb;">()</span><span style="color: #494949;">)</span>
</pre>
</div>
<p>
Collection nodes can be useful if certain requests are only efficient if they are batch-processed, or for collecting all elements within a set of a known size.
</p>
</div>
</div>
<div id="outline-container-org7ad0899" class="outline-3">
<h3 id="org7ad0899">State Nodes</h3>
<div class="outline-text-3" id="text-org7ad0899">
<p>
Now obviously you might want to store some state in this graph. So of course there are state nodes. State nodes act similarly to refs and simply serve to store some set of state such that it can be accessed (and modified) across the network.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defsnode</span> <span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orge21e17b" class="outline-3">
<h3 id="orge21e17b">I/O Nodes</h3>
<div class="outline-text-3" id="text-orge21e17b">
<p>
I/O to DIGRAPH is represented as input and output nodes. Currently, since I have yet to implement the silicon version, DIGRAPH takes input and output nodes as follows.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def</span> <span style="font-style: italic;">out</span> <span style="color: #bbb;">(</span>output-node <span style="color: #E53935;">:port</span> 80<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def</span> <span style="font-style: italic;">in</span> <span style="color: #bbb;">(</span>input-node <span style="color: #E53935;">:port</span> 80<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
<p>
By default inputs are parsed to EDNs, however, with the <code>:format</code> option you can receive them as strings, JSONs, XML, or any other such thing. Input and output nodes are also the only nodes visible to external computers so if you want to use log4j to helpfully add extra code, you might want to make a special output node.
</p>
<p>
Inputs in digraph look like this:
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">{</span><span style="color: #E53935;">:client</span> <span style="color: #494949;">"12.313.1212"</span> <span style="color: #E53935;">:request</span> some-data<span style="color: #494949;">}</span>
</pre>
</div>
<p>
Likewise, to output to something, you do the same:
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">{</span><span style="color: #E53935;">:client</span> <span style="color: #494949;">"12.313.1212"</span> <span style="color: #E53935;">:request</span> some-data<span style="color: #494949;">}</span>
</pre>
</div>
<p>
I/O operations are also, by default, all conducted through the same IP address. However, should you want to, you can have multiple I/O nodes with different IP addresses.
</p>
</div>
</div>
<div id="outline-container-org3705110" class="outline-3">
<h3 id="org3705110">A Note on Cyclic Graphs</h3>
<div class="outline-text-3" id="text-org3705110">
<p>
Should you create a cyclic graph, it's a good idea to envision it and the rest of your system as a control system. List elements passed through the graph can be considered a .
</p>
<p>
Therefore, you want the total number of messages sent through the graph to approach zero as time goes to infinity. In the most basic sense this means that you should have filter or collection functions within each cycle, reducing the total number of messages.
</p>
<p>
However, it is very possible that some set of messages may still exist.
</p>
</div>
</div>
</div>
<div id="outline-container-org7862557" class="outline-2">
<h2 id="org7862557">Plans</h2>
<div class="outline-text-2" id="text-org7862557">
</div>
<div id="outline-container-orgd3b52ed" class="outline-3">
<h3 id="orgd3b52ed">GraalVM Compilation</h3>
<div class="outline-text-3" id="text-orgd3b52ed">
<p>
GraalVM has a much faster startup time than regular clojure, which is generally assumed to be something you sort of just start and leave running as a high-throughput server. This would allow me to cut down on buffer sizes and increase scaling rates.
</p>
</div>
</div>
<div id="outline-container-orgf8866c0" class="outline-3">
<h3 id="orgf8866c0">Subgraphs</h3>
<div class="outline-text-3" id="text-orgf8866c0">
<p>
I would like to add subgraphs as a feature, so you can treat graphs themselves as nodes.
</p>
</div>
</div>
<div id="outline-container-org3e19a70" class="outline-3">
<h3 id="org3e19a70">Live Updates</h3>
<div class="outline-text-3" id="text-org3e19a70">
<p>
I would also like to have the system update live, with graph node.s2
</p>
</div>
</div>
</div>
<div id="outline-container-org0b86369" class="outline-2">
<h2 id="org0b86369">Changelog</h2>
</div>
<div id="outline-container-org52c1884" class="outline-2">
<h2 id="org52c1884">Implementation</h2>
<div class="outline-text-2" id="text-org52c1884">
</div>
<div id="outline-container-org87b0c49" class="outline-3">
<h3 id="org87b0c49">Server Functions</h3>
<div class="outline-text-3" id="text-org87b0c49">
<p>
To start out we need to define some functions to process HTTPS requests. Currently I am using the http-kit library for this, though I might decide to go for something else.
</p>
<div class="org-src-container">
<pre class="src src-clojure">
</pre>
</div>
</div>
</div>
<div id="outline-container-org6e66f40" class="outline-3">
<h3 id="org6e66f40">Macros</h3>
<div class="outline-text-3" id="text-org6e66f40">
<p>
Of course, no Clojure library would be complete without macros.
</p>
<pre class="example">
</pre>
</div>
<div id="outline-container-org0bb05f9" class="outline-4">
<h4 id="org0bb05f9">defgraph</h4>
<div class="outline-text-4" id="text-org0bb05f9">
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defmacro</span> <span style="font-weight: bold; font-style: italic;">defgraph</span> <span style="color: #bbb;">[</span>graph-name &args<span style="color: #bbb;">]</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defgraph</span> <span style="font-weight: bold; font-style: italic;">graph-a</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> in a b c d<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> d c<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> c a b out<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgc12093e" class="outline-4">
<h4 id="orgc12093e">defdag</h4>
<div class="outline-text-4" id="text-orgc12093e">
<p>
Now of course you might want to restrict yourself a bit so you don't end up with endless feedback loops in your graphs. Therefore you can define a directed acyclic graph, which is a restricted set of the more general graph form and checks for cycles within your graph.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defmacro</span> <span style="font-weight: bold; font-style: italic;">defdag</span> <span style="color: #bbb;">[</span>graph-name &args<span style="color: #bbb;">]</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defgraph</span> <span style="font-weight: bold; font-style: italic;">graph-b</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> in a b c d<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> d c<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> c a b out<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgf7b0e88" class="outline-3">
<h3 id="orgf7b0e88">Compilation</h3>
<div class="outline-text-3" id="text-orgf7b0e88">
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defmacro</span> <span style="font-weight: bold; font-style: italic;">compile-project</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Last Modified: 2021-W52-1 23:10</p><p class="creator">Generated Using: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 27.2 (<a href="https://orgmode.org">Org</a> mode 9.4.6)</p><p class="license">Except where otherwise noted content on <a href="https://cons.dev">cons.dev</a> is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/" rel="license">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p>
</div>
</body>
</html>