<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>English | Gamlor</title>
	<atom:link href="https://www.gamlor.info/wordpress/category/english/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gamlor.info/wordpress</link>
	<description>thoughts about programming, tv-series and other geeky stuff.</description>
	<lastBuildDate>Thu, 11 Mar 2021 08:42:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Korean Hangul Stopped Working After IBus Update to 1.5.18? A Work Around.</title>
		<link>https://www.gamlor.info/wordpress/2018/05/ibus-1-5-18-stopped-working-en/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Sun, 06 May 2018 00:47:26 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3713</guid>

					<description><![CDATA[<p>When I&#8217;m using Linux I use IBus to write Korean. A few days ago when I updated my Manjaro installation writing Korean stopped working. After booting everything looked fine. The&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2018/05/ibus-1-5-18-stopped-working-en/">Korean Hangul Stopped Working After IBus Update to 1.5.18? A Work Around.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>When I&#8217;m using Linux I use <a href="ttps://github.com/ibus/ibus/">IBus</a> to write Korean. A few days ago when I updated my <a href="https://manjaro.org/">Manjaro</a> installation writing Korean stopped working. After booting everything looked fine. The IBus tray icon was there, switching languages with Win+Space seemed to work.</p>
<div id="attachment_3695" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/icon-ok.png"><img decoding="async" aria-describedby="caption-attachment-3695" class="size-medium wp-image-3695" src="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/icon-ok-300x146.png" alt="OK!" width="300" height="146" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/icon-ok-300x146.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/icon-ok.png 679w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3695" class="wp-caption-text">OK!</p></div>
<div id="attachment_3697" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/switch-ok.png"><img decoding="async" aria-describedby="caption-attachment-3697" class="size-medium wp-image-3697" src="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/switch-ok-300x135.png" alt="Win+Space=OK" width="300" height="135" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/switch-ok-300x135.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/switch-ok.png 603w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3697" class="wp-caption-text">Win+Space=OK</p></div>
<p>However, when I started to type the IBus icon suddenly changed and it wrote in English. I didn&#8217;t know that icon and it seemed strange. There was no error message. IBus just always switched to that icon and then wrote in the English alphabet.</p>
<div id="attachment_3717" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/not-ok-en.png"><img decoding="async" aria-describedby="caption-attachment-3717" class="size-medium wp-image-3717" src="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/not-ok-en-300x121.png" alt="What is this?" width="300" height="121" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/not-ok-en-300x121.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/not-ok-en.png 763w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3717" class="wp-caption-text">What is this?</p></div>
<p>Well, first I searched the Internet without success. I found only old entries which did no help. So, maybe there are logs? I couldn&#8217;t find any IBus log in /var/logs or something like that. However, the IBus man page told about a &#8211;verbose flag. So, I used that and tada, there were error messages:</p>
<pre>[gamlor@gamlor-t470p ~]$ ibus-daemon --verbose -r &amp;
[4] 13270
[gamlor@gamlor-t470p ~]$ 
(ibus-daemon:13170): GLib-WARNING **: 21:33:08.140: GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). See the documentation of g_child_watch_source_new() for possible causes.
(ibus-engine-hangul:13296): IBUS-WARNING **: 21:33:08.224: org.freedesktop.IBus.Config.GetValue: GDBus.Error:org.freedesktop.DBus.Error.Failed: Config value [engine/hangul:on-keys] does not exist.
(ibus-engine-hangul:13296): IBUS-WARNING **: 21:33:08.224: org.freedesktop.IBus.Config.GetValue: GDBus.Error:org.freedesktop.DBus.Error.Failed: Config value [engine/hangul:off-keys] does not exist.
(ibus-daemon:13270): GLib-CRITICAL **: 21:33:08.229: g_variant_unref: assertion 'value != NULL' failed
(ibus-ui-gtk3:13277): IBUS-WARNING **: 21:33:13.143: ibus_bus_call_sync: org.freedesktop.DBus.Properties.Get: GDBus.Error:org.freedesktop.DBus.Error.Failed: No global engine.
</pre>
<p>Oh&#8230;&#8217;assert failed&#8217; doesn&#8217;t sound good. And whenever I tried to write Korean, the `bus_bus_call_sync&#8230;No global engine` message got printed. So I searched for that error message and found this <a href="https://github.com/ibus/ibus/issues/2004">Github issue</a>. There is a work around: When configuring an Emoji selection key, the issue goes away. Strange. So, I did that and everything worked again. Here&#8217;s how: IBus Preference -> Emoji -> &#8230; Button -> Select a impossible key combination -> Add -> Done!</p>
<div id="attachment_3707" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/fix-all.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3707" src="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/fix-all-1024x224.png" alt="Work around" width="700" height="153" class="size-large wp-image-3707" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/fix-all-1024x224.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/fix-all-300x66.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2018/05/fix-all-768x168.png 768w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3707" class="wp-caption-text">Work around</p></div>
<p>The end</p><p>The post <a href="https://www.gamlor.info/wordpress/2018/05/ibus-1-5-18-stopped-working-en/">Korean Hangul Stopped Working After IBus Update to 1.5.18? A Work Around.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Async Database Connector for Java (ADBCJ) on JCenter.</title>
		<link>https://www.gamlor.info/wordpress/2017/10/async-database-connector-for-java-adbcj-on-jcenter/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Tue, 24 Oct 2017 11:55:57 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[adbcj]]></category>
		<category><![CDATA[async]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3660</guid>

					<description><![CDATA[<p>Due to lack of time and interest, ADBCJ is in &#8216;maintenance&#8217; mode. However, I still improve it from time to time =). ADBCJ in JCenter Finally, ADBCJ is in a&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/10/async-database-connector-for-java-adbcj-on-jcenter/">Async Database Connector for Java (ADBCJ) on JCenter.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Due to lack of time and interest, ADBCJ is in &#8216;maintenance&#8217; mode. However, I still improve it from time to time =).</p>
<div id="attachment_3669" style="width: 394px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/adbcj-icu.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3669" class=" wp-image-3669" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/adbcj-icu.jpg" alt="" width="384" height="642" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/adbcj-icu.jpg 574w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/adbcj-icu-179x300.jpg 179w" sizes="(max-width: 384px) 100vw, 384px" /></a><p id="caption-attachment-3669" class="wp-caption-text">ADBCJ will be fine ^.^</p></div>
<h2>ADBCJ in JCenter</h2>
<p>Finally, ADBCJ is in a decent Maven repository! That is a long standing to do crossed of the list. First, you&#8217;ll need to add JCenter to your projects maven repos. Unless your build tool has the JCenter by default.<br />
For Maven:</p>
<pre><code>&lt;repository&gt;
 &lt;snapshots&gt;
 &lt;enabled&gt;false&lt;/enabled&gt;
 &lt;/snapshots&gt;
 &lt;id&gt;central&lt;/id&gt;
 &lt;name&gt;bintray&lt;/name&gt;
 &lt;url&gt;https://jcenter.bintray.com&lt;/url&gt;
&lt;/repository&gt;
</code></pre>
<p>After than you include ADBCJ as a dependency.</p>
<p>MySQL driver:</p>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.adbcj&lt;/groupId&gt;
    &lt;artifactId&gt;adbcj-api&lt;/artifactId&gt;
    &lt;version&gt;0.9&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.adbcj&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-async-driver&lt;/artifactId&gt;
    &lt;version&gt;0.9&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<p>H2 driver:</p>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.adbcj&lt;/groupId&gt;
    &lt;artifactId&gt;adbcj-api&lt;/artifactId&gt;
    &lt;version&gt;0.9&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.adbcj&lt;/groupId&gt;
    &lt;artifactId&gt;h2-async-driver&lt;/artifactId&gt;
    &lt;version&gt;0.9&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<h2>Changes&lt;/h2</h2>
<h3>Java 8</h3>
<p>Recent ADBCJ versions requires Java 8. Instead of ADBCJ&#8217;s own future implementations, methods now return Java 8&#8217;s <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html">completable futures</a> =).</p>
<h3>Callback API</h3>
<p>Java 8&#8217;s futures are not every bodies taste. Especially other JVM language have their own futures and concurrency constructs. Or you might really do not want a future based control flow. So, I changed ADBCJ&#8217;s basic API to be callback driven. That allows to use other concurrency constructs without going through Java futures as intermediate step. The Java 8 completable future methods are also implemented in term of these futures.</p>
<h2>Examples on Github</h2>
<p>Examples how to use ADBCJ are on <a href="https://github.com/gamlerhart/adbcj/blob/master/Readme.md">GitHub</a>.</p><p>The post <a href="https://www.gamlor.info/wordpress/2017/10/async-database-connector-for-java-adbcj-on-jcenter/">Async Database Connector for Java (ADBCJ) on JCenter.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Need a CDN? Try out edgemesh.com.</title>
		<link>https://www.gamlor.info/wordpress/2017/10/need-a-cdn-try-out-edgemesh-com/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Mon, 09 Oct 2017 14:01:24 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[edgemesh]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3627</guid>

					<description><![CDATA[<p>Do you need a CDN for your website? Maybe you want to try edgemesh.com. The basic subscription is free! Start First sign up on edgemesh.com. Then embed this script into&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/10/need-a-cdn-try-out-edgemesh-com/">Need a CDN? Try out edgemesh.com.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Do you need a CDN for your website? Maybe you want to try edgemesh.com. The basic subscription is free!</p>
<h2>Start</h2>
<p>First sign up on <a href="https://edgemesh.com/">edgemesh.com</a>. Then embed this script into your website:</p>
<script src="https://gist.github.com/d71405db7a446220a11590dac0246a3b.js?file=edge-mesh.html"></script><noscript><pre><code class="language-html html">&lt;script
    type=&quot;application/javascript&quot;
    src=&quot;https://sig.edgeno.de/edgemesh.client.min.js&quot;
    onload=&quot;window.edgemesh = new Edgemesh()&quot;&gt;
&lt;/script&gt;</code></pre></noscript>
<p>Done. Really!</p>
<h2>So, how does Edgemesh work?</h2>
<p>A normal CDN has tons of servers all over the world. Those server caches your images, CSS and Javascript. So, visitors can download your content quickly from a close CDN server. However, if there is no CDN server in your visitors area, they won`t benefit from quick downloads. And CDN servers are not free!<br />
<div id="attachment_3649" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3649" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final-1024x696.jpg" alt="" width="700" height="476" class="size-large wp-image-3649" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final-1024x696.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final-300x204.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final-768x522.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/classic-cdn-en-final.jpg 1177w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3649" class="wp-caption-text">Classic CDN</p></div><br />
Edgemesh works differently. Nowadays our phones and computers are really fast. Our web browsers are powerful. Browsers have an IndexeDB database and can do P2P networking with WebRTC. This is what Edgemesh uses. When visitors visit a website, Edgemesh stores some content in their browser. When another nearby visitor needs the same content, they download it from other visitor`s browsers. Therefore, if you have many visitors, they can fetch the content quickly from each other.</p>
<p><div id="attachment_3653" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3653" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final-1024x613.jpg" alt="" width="700" height="419" class="size-large wp-image-3653" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final-1024x613.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final-300x180.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final-768x460.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/edge-mesh-en-final.jpg 1336w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3653" class="wp-caption-text">Edgemesh</p></div><br />
However, we can not trust the visitor`s internet connection. Maybe it is very slow, maybe it is suddenly interrupted. So, Edgemesh prefetches some content and falls back to regular downloads if it is to slow. Also, you can add Edgemesh &#8216;supernodes&#8217;, which act a bit like a regular CDN servers. Furthermore, you can combine Edgemesh with a traditional CDN.</p>
<h2>Does it work?</h2>
<p>Yes. This blog has close to no visitors, yet Edgemesh manages to store and distribute some content:<br />
<div id="attachment_3640" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3640" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1-1024x576.png" alt="" width="700" height="394" class="size-large wp-image-3640" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1-1024x576.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1-300x169.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1-768x432.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/10/gamlor-on-edgemesh-1.png 1920w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3640" class="wp-caption-text">This sites Edgemesh network</p></div><br />
Just try it out on your site. =)</p><p>The post <a href="https://www.gamlor.info/wordpress/2017/10/need-a-cdn-try-out-edgemesh-com/">Need a CDN? Try out edgemesh.com.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Adding Timestamp to Logs</title>
		<link>https://www.gamlor.info/wordpress/2017/09/adding-timestamp-to-logs/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Wed, 27 Sep 2017 09:24:46 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3592</guid>

					<description><![CDATA[<p>How many small script or process do you have which just log to stdout/stderr? A few, dozens? Their running as cronjobs or service? Stashing the logs somewhere, like: ./produces-some-log.sh 2>&#038;1&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/09/adding-timestamp-to-logs/">Adding Timestamp to Logs</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>How many small script or process do you have which just log to stdout/stderr? A few, dozens?<br />
Their running as cronjobs or  service?<br />
Stashing the logs somewhere, like:</p>
<pre>
./produces-some-log.sh 2>&1 > log-of-my-script.log
</pre>
<p>Do you have time stamps on those logs?<br />
If not, it is trivial to add. You just have to pipe the log through a time stamp tool.</p>
<div id="attachment_3600" style="width: 823px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/09/time-stamp.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3600" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/09/time-stamp.jpg" alt="" width="813" height="353" class="size-full wp-image-3600" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/09/time-stamp.jpg 813w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/09/time-stamp-300x130.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/09/time-stamp-768x333.jpg 768w" sizes="(max-width: 813px) 100vw, 813px" /></a><p id="caption-attachment-3600" class="wp-caption-text">Timestamp your lines</p></div>
<h2>Linux: ts</h2>
<p>On most Linux distros there the `ts` tool. If it is not installed, it is usually in the &#8216;moreutils&#8217; package. So get it via `apt-get`, `yum`, `pacman` or whatever you`re distro uses.</p>
<p>Then, pipe the output through `ts`:</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1                                          
We are making progress. We are at step 1/5         
And some other info about the system:  13:39:24 up 2:10, 2 users, load average: 1.44, 1.74, 1.76       
We are making progress. We are at step 2/5         
And some other info about the system:  13:39:25 up 2:10, 2 users, load average: 1.44, 1.74, 1.76       
We are making progress. We are at step 3/5         
....
</pre>
<p>Will become:</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1 | ts                                     
Sep 25 13:39:30 We are making progress. We are at step 1/5                                             
Sep 25 13:39:30 And some other info about the system:  13:39:30 up 2:10, 2 users, load average: 1.65, 1.78, 1.77                                                                                               
Sep 25 13:39:31 We are making progress. We are at step 2/5                                             
Sep 25 13:39:31 And some other info about the system:  13:39:31 up 2:10, 2 users, load average: 1.65, 1.78, 1.77                                                                                               
Sep 25 13:39:31 We are making progress. We are at step 3/5                                             
...          
</pre>
<p>You can specify a date format string to have more clear format:</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1 | ts '%Y-%m-%dT%T%z'
2017-09-25T22:47:25+0900 We are making progress. We are at step 1/5
2017-09-25T22:47:25+0900 And some other info about the system:  22:47:25 up 2:18, 2 users, load average: 1.25, 1.29, 1.53
2017-09-25T22:47:26+0900 We are making progress. We are at step 2/5
2017-09-25T22:47:26+0900 And some other info about the system:  22:47:26 up 2:18, 2 users, load average: 1.25, 1.29, 1.53
...
</pre>
<p>Last, I recommend using the UTC time zone, to avoid confusion. Expecially when your servers are all over the world. Or you need to cross reference time stamps with other logs.<br />
If your server isn`t set to UTC, you can set the `TZ` enviroment variable:</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ export TZ=UTC
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1 | ts '%Y-%m-%dT%T%z'
2017-09-25T13:49:54+0000 We are making progress. We are at step 1/5
2017-09-25T13:49:54+0000 And some other info about the system:  13:49:54 up 2:21, 2 users, load average: 0.66, 1.13, 1.44
2017-09-25T13:49:55+0000 We are making progress. We are at step 2/5
...
</pre>
<p>For more details, check the <a href="https://linux.die.net/man/1/ts">man pages</a>.</p>
<h2>For all Unix-like systems, AWK to the rescue!</h2>
<p>BSD, illumos or some other Unix like system? Maybe there no `ts` util around? Good old awk has got you covered. On each line, print the date, then the rest of the line.</p>
<p>This method is more portable. AWK is installed most systems. So, if you plan do distribute your script, this is the way to go.</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1 | awk '{ print strftime("%Y-%m-%dT%T%z"), $0;  }'                                                                                                     
2017-09-25T22:57:54+0900 We are making progress. We are at step 1/5                                    
2017-09-25T22:57:54+0900 And some other info about the system:  22:57:54 up 2:29, 2 users, load average: 1.29, 1.23, 1.39                                                                                      
2017-09-25T22:57:55+0900 We are making progress. We are at step 2/5                                    
...
</pre>
<p>Again, I recommend using UTC. Your server probably already uses UTC anyway:</p>
<pre>
[gamlor@gamlor-manjaro log-util]$ export TZ=UTC    
[gamlor@gamlor-manjaro log-util]$ ./produces-some-log.sh 2>&1 | awk '{ print strftime("%Y-%m-%dT%T%z"), $0;  }'                                                                                                     
2017-09-25T13:59:23+0000 We are making progress. We are at step 1/5                                    
2017-09-25T13:59:23+0000 And some other info about the system:  13:59:23 up 2:30, 2 users, load average: 1.09, 1.15, 1.35                                                                                      
2017-09-25T13:59:24+0000 We are making progress. We are at step 2/5                                    
...                                  
</pre>
<p>That`s it =).<br />
Thanks for the Stackoverflow <a href="https://stackoverflow.com/questions/21564/is-there-a-unix-utility-to-prepend-timestamps-to-stdin">answers</a>, which include both solutions.</p><p>The post <a href="https://www.gamlor.info/wordpress/2017/09/adding-timestamp-to-logs/">Adding Timestamp to Logs</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Java&#8217;s Enum.values() Hidden Allocations</title>
		<link>https://www.gamlor.info/wordpress/2017/08/javas-enum-values-hidden-allocations/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Thu, 31 Aug 2017 13:47:29 +0000</pubDate>
				<category><![CDATA[42]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[gc]]></category>
		<category><![CDATA[performance]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3562</guid>

					<description><![CDATA[<p>I recently profiled an app of mine. During profiling, I&#8217;ve noticed tons of array allocations. Something like: Well easy, a quick grep for TypeInfo[] array. Nothing. Ah, quick grep for&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/08/javas-enum-values-hidden-allocations/">Java’s Enum.values() Hidden Allocations</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I recently profiled an app of mine. During profiling, I&#8217;ve noticed tons of array allocations. Something like:</p>
<p><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness.png"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness-1024x332.png" alt="" width="700" height="227" class="aligncenter size-large wp-image-3570" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness-1024x332.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness-300x97.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness-768x249.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocation-madness.png 1311w" sizes="(max-width: 700px) 100vw, 700px" /></a></p>
<p>Well easy, a quick grep for TypeInfo[] array. Nothing. Ah, quick grep for TypeInfo collections. Nothing! Huh? Where the hell do I allocate the array then?<br />
Ok, more profiling! So, I enabled flight recorder with &#8216;-XX:+UnlockCommercialFeatures -XX:+FlightRecorder&#8217;. Then did a recording with <a href="http://www.oracle.com/technetwork/java/javaseproducts/mission-control/index.html">Java Mission Control</a>, capturing the allocation stack traces:</p>
<p><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values.png"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values-1024x507.png" alt="" width="700" height="347" class="aligncenter size-large wp-image-3572" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values-1024x507.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values-300x149.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values-768x380.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/allocated-by-enum-values.png 1456w" sizes="(max-width: 700px) 100vw, 700px" /></a></p>
<p>Ok, the TypeInfo.values() method allocates the memory. TypeInfo is a enum, and I&#8217;m using the built in values() method. The code looked something like this:</p>
<script src="https://gist.github.com/d3f5a7f143dbc894b4f43c4fcbaae79f.js?file=Enum-Allocation-Example.java"></script><noscript><pre><code class="language-java java">package info.gamlor.blog;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

enum TypeInfo {
    UNKNOWN(0),
    INT(1),
    STRING(2);

    private final int id;

    TypeInfo(int id) {
        this.id = id;
    }

    public static TypeInfo findType(int type){
        for (TypeInfo t : values()){
            if(t.id == type){
                return t;
            }
        }
        return UNKNOWN;
    }
}

public class Main {
    private static Random rnd = new Random();

    public static void main(String[] args) throws Exception {
        List&lt;TypeInfo&gt; parsedData = new ArrayList&lt;&gt;();
        for (int i = 0; i &lt; 1000000000; i++) {
            int idParsedFromWire = readTypeIdFromData(rnd);

            TypeInfo type = TypeInfo.findType(idParsedFromWire);

            // Pretend we use the type for the exampe
            parsedData.add(type);
            consumeData(parsedData);
        }
        System.out.println(parsedData.size());
    }

    private static void consumeData(List&lt;TypeInfo&gt; parsedData) {
        // Parsed data is consumed
        if(rnd.nextBoolean()){
            parsedData.clear();
        }
    }

    private static int readTypeIdFromData(Random rnd) throws InterruptedException {
        // Data comes from the wire....let&#039;s run this example a bit slower
        int idParsedFromWire = rnd.nextInt(16);
        Thread.yield();
        return idParsedFromWire;
    }
}
</code></pre></noscript>
<p>Do you see the allocation? Why should it allocate that many arrays? The Enum values are constant, so it should be able to initialize an array once?<br />
Ok, let&#8217;s take a closer look and decompile the class file:</p>
<pre>
javap -c TypeInfo.class | grep -A 10 values
</pre>
<p>And we get:</p>
<pre>
  public static info.gamlor.blog.TypeInfo[] values();
    Code:
       0: getstatic     #1                  // Field $VALUES:[Linfo/gamlor/blog/TypeInfo;
       3: invokevirtual #2                  // Method "[Linfo/gamlor/blog/TypeInfo;".clone:()Ljava/lang/Object;
       6: checkcast     #3                  // class "[Linfo/gamlor/blog/TypeInfo;"
       9: areturn
</pre>
<p>As we can see, it deferences a static array of the Enum values. Then it clones that array before returning it, causing an array allocation. Why does it do that? It is a defensive copy:<br />
Java&#8217;s arrays are a mutable. If values() just returns the reference to the original array, then some code might change the array&#8217;s content. That creates havoc, since it would change what Enum.values() returns. Therefore, the defensive copy.</p>
<div id="attachment_3573" style="width: 958px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/enum-copies.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3573" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/enum-copies.jpg" alt="" width="948" height="500" class="size-full wp-image-3573" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/enum-copies.jpg 948w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/enum-copies-300x158.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/enum-copies-768x405.jpg 768w" sizes="(max-width: 948px) 100vw, 948px" /></a><p id="caption-attachment-3573" class="wp-caption-text">Safety First, Copy It</p></div>
<p>So, after seeing this, it is easy to fix our code. We call Enum.values() once, cache the array and use it for the parsing:</p>
<script src="https://gist.github.com/d3f5a7f143dbc894b4f43c4fcbaae79f.js?file=Fix.java"></script><noscript><pre><code class="language-java java">// Enum.values() does a defensive copy and allocates an array on each call
// To avoid that allocation, we call values() only once
private static final TypeInfo[] ALL_VALUES = values();

public static TypeInfo findType(int type){
    for (TypeInfo t : ALL_VALUES){
        if(t.id == type){
            return t;
        }
    }
    return UNKNOWN;
}</code></pre></noscript>
<p>Et voila, the allocations are gone =)</p>
<p><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed.png"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed-1024x213.png" alt="" width="700" height="146" class="aligncenter size-large wp-image-3574" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed-1024x213.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed-300x63.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed-768x160.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/08/fixed.png 1300w" sizes="(max-width: 700px) 100vw, 700px" /></a></p><p>The post <a href="https://www.gamlor.info/wordpress/2017/08/javas-enum-values-hidden-allocations/">Java’s Enum.values() Hidden Allocations</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Deploying JVM in tiny containers, be carefull!</title>
		<link>https://www.gamlor.info/wordpress/2017/04/deploying-jvm-in-tiny-containers-be-carefull/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Tue, 25 Apr 2017 14:59:39 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[joyent]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[triton]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3509</guid>

					<description><![CDATA[<p>I`ve deployed my rohrli.gamlor.info service into the smallest possible triton container. Except me, noone is going to use it anyway ^-^. This container has 128Mbyte of memory, and 1/16th CPU&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/04/deploying-jvm-in-tiny-containers-be-carefull/">Deploying JVM in tiny containers, be carefull!</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I`ve deployed my <a href="https://rohrli.gamlor.info">rohrli.gamlor.info</a> service into the smallest possible triton container. Except me, noone is going to use it anyway ^-^. This container has 128Mbyte of memory, and 1/16th CPU time. The OpenJDK JVM is known for consuming tons of memory. And it is somewhat true. However, the JVM also runs in a small container. In this blog post I give some recommendations. The problems exists in small Docker and Triton containers. I show everything for both.<br />
<div id="attachment_3551" style="width: 810px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-usage-en-1.jpeg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3551" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-usage-en-1.jpeg" alt="Chrome &amp; JVM eat memory generously" width="800" height="567" class="size-full wp-image-3551" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-usage-en-1.jpeg 800w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-usage-en-1-300x213.jpeg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-usage-en-1-768x544.jpeg 768w" sizes="(max-width: 800px) 100vw, 800px" /></a><p id="caption-attachment-3551" class="wp-caption-text">Chrome &#038; JVM eat memory generously</p></div></p>
<h2>Web App Example</h2>
<p>The web app is just a &#8216;Hello World&#8217; app. For better explaination, it also consumes tons of memory. I created the example in Scala, but the other JVM languages have the same issue. The source code for the example is <a href="https://github.com/gamlerhart/blog-post-examples/tree/master/jvm-in-small-containers">here</a>.<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=Hello-Basics.scala"></script><noscript><pre><code class="language-scala scala">/** 
 * Snippet, memory limits 
 */
// Limit the amount of items in memory for this example.
// So, max ~192*256k=48MBytes
val maxMemoryItems = 192
val memoryPerItem = 256 * 1024
val memoryWasting = new ArrayBlockingQueue[Array[Byte]](maxMemoryItems)

/** 
 * Snippet, request handling
 */
// On each request, consume some memory.
// And keep things in memory to simulate memory use
case &quot;/&quot; :: Nil =&gt; {
    // On each request, consume some memory.
    // And keep things in memory to simulate memory use
    val chunkOfMemory = Array.ofDim[Byte](memoryPerItem)
    var addedToQueue = memoryWasting.offer(chunkOfMemory)

    // Throw things away until we&#039;ve space
    while (!addedToQueue) {
        memoryWasting.poll()
        addedToQueue = memoryWasting.offer(chunkOfMemory)
    }

    val createdSoFar = createdItemsCounter.incrementAndGet()
    response.getWriter.write(
        s&quot;&quot;&quot;
            |{
            |&quot;title&quot;:&quot;Hello World! Let&#039;s use some memory&quot;,
            |&quot;created-overall&quot;:&quot;$createdSoFar&quot;,
            |&quot;queue-size&quot;:&quot;${memoryWasting.size()}&quot;,
            |&quot;&quot;:&quot;Hello. I&#039;m so memory hungry. kthxbye!&quot;
            |}
        &quot;&quot;&quot;.stripMargin)
}</code></pre></noscript><br />
We compile and package the program into a Docker container. The Docker file is simple:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=version1.Dockerfile"></script><noscript><pre><code class="language-dockerfile dockerfile">FROM openjdk:8u121-jdk-alpine

# Assume already compiled for now
COPY target/scala-2.12/useless-demo-service.jar /app/useless-demo-service.jar

EXPOSE 8080
CMD java -jar /app/useless-demo-service.jar
</code></pre></noscript><br />
The we create the image with `build` and run it with `run`. With regular Docker we restrict the memory with the &#8216;-m 128m&#8217; option to 128Mbyte. And with &#8216;&#8211;cpus 0.065&#8217; we only give very little CPU time.<br />
When using Triton, the &#8216;-m 128m&#8217; option will find a <a href="https://apidocs.joyent.com/docker/features/resources">sufficient large</a> compute instance. Alternativly, you also can use &#8216;&#8211;label com.joyent.package=g4-highcpu-128M&#8217; to create a tiny instance.<br />
Once we started out container, we create some load with the &#8216;watch&#8217; and &#8216;curl&#8217; commands. Then, let`s watch the logs.<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=first-run.sh"></script><noscript><pre><code class="language-shell shell">##
# Local docker run 
##
sudo docker run -d -m 128m --cpus 0.065 --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:1
# Start to follow the logs
sudo docker logs -f jvm-on-small-container
# Then, start the simple load, in another termial
watch -n 0.01 curl http://localhost:8080/

##
# Joyent Triton run
##
eval &quot;$(triton env)&quot;
docker run -d -m 128m --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:1
# Get the IP
docker inspect --format &#039;{{ .NetworkSettings.IPAddress }}&#039; jvm-on-small-container
# Start to follow the logs
docker logs -f jvm-on-small-container
# Then, start the simple load, in another termial
watch -n 0.01 curl http://{ip-from-above}:8080/
</code></pre></noscript></p>
<h2>First Issue: Program Dies</h2>
<p>The Triton instance won`t expirience any issue. But the plain Docker instance (Linux 4.10, Docker 17.04) suddenly stops working. =( The program got killed.<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=unexpected-process-death.txt"></script><noscript><pre><code class="language-text text">[root@gamlor-manjaro useless-demo-service]# docker run -m 128m --cpus 0.065 -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:1
2017-04-20 12:58:20.248:INFO::main: Logging initialized @5900ms to org.eclipse.jetty.util.log.StdErrLog
2017-04-20 12:58:23.348:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT
2017-04-20 12:58:30.650:INFO:oejs.AbstractConnector:main: Started ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-04-20 12:58:30.748:INFO:oejs.Server:main: Started @16602ms
Killed
</code></pre></noscript><br />
Hmmm&#8230;.Why did it got killed? Aha&#8230;the memory is small, so we might ran out of memory and got killed. We can, while the container runs, inspect the memory usage of the JVM with `jstat`:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=inspect-memory.sh"></script><noscript><pre><code class="language-shell shell">##
# Local docker run 
##
# Get memory usage of the running java process
sudo docker exec jvm-on-small-container sh -c &#039;jstat -gccapacity `pgrep java`&#039;
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
84480.0 1354240.0 84480.0 10240.0 10240.0 64000.0 169472.0 2708992.0 169472.0 169472.0 0.0 1056768.0 4480.0 0.0 1048576.0 384.0 1 0


##
# Joyent Triton run
##
# Get memory usage of the running java process
eval &quot;$(triton env)&quot;
docker exec jvm-on-small-container sh -c &#039;jstat -gccapacity `pgrep java`&#039;
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
  2688.0  21824.0  21824.0 2176.0 2176.0  17472.0     5504.0    43712.0    43712.0    43712.0      0.0 1060864.0  12544.0      0.0 1048576.0   1536.0     15    69
</code></pre></noscript><br />
<div id="attachment_3547" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en.jpeg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3547" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en-1024x478.jpeg" alt="The penguin and whale are dangerous. Be careful!" width="700" height="327" class="size-large wp-image-3547" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en-1024x478.jpeg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en-300x140.jpeg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en-768x358.jpeg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/memory-en.jpeg 1400w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3547" class="wp-caption-text">The penguin and whale are dangerous. Be careful!</p></div><br />
<a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html">jstat</a> is a bit confusing. All numbers are in KByte. The JVM has a few memory pools and each memory pool has a minimum (**MN), maximum (**MX) and current size (**C).<br />
So, inside the regular Docker container it create really big memory pools. On my computer (16GB, Linux 4.10, Docker 17.04), OGCMX (old generation heap) memory is about 2.5GByte. However, on the Triton instance it is about 40Mybte large. So, with a 2.5GByte pool, if it actually uses more than 128MByte, it will die. For now, Docker just kills processes which use too much memory. However, the JVM sees all the hosts memory, so it creates giant memory pools.<br />
However, the Triton container lies more convincingly, so the JVM sees the containers memory sizes and creates a sufficient small memory pool.<br />
Well, there a solution to this issue. We just configure a small memory size with the `-Xmx` option. Plus I configure the JVM such that when it runs out of memory, it dumps the memory and dies.<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=version2.Dockerfile"></script><noscript><pre><code class="language-dockerfile dockerfile">FROM openjdk:8u121-jdk-alpine

# Assume already compiled for now
COPY target/scala-2.12/useless-demo-service.jar /app/useless-demo-service.jar

# Defaults for a tiny container
ENV MEMORY=&quot;64m&quot;

EXPOSE 8080

CMD java -Xmx$MEMORY -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=&quot;kill -9 %p&quot; \
    -jar /app/useless-demo-service.jar</code></pre></noscript><br />
After doing this, the JVM runs in the Docker container without any issue.</p>
<h2>So Many Threads</h2>
<p>Now, we configured the memory properly. However, there maybe more things we can configure properly? So, let`s see what threads are runing in the container with `jstack`:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=inspect-threads-1st.sh"></script><noscript><pre><code class="language-shell shell">##
# Local docker run 
##
# Run second version of our container
sudo docker run -d -m 128m --cpus 0.065 --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:2
# List the threads running
sudo docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
&quot;qtp791452441-23&quot; #23 prio=5 os_prio=0 tid=0x000056473bc03800 nid=0x42 waiting on condition [0x00007fefe4931000]
&quot;Attach Listener&quot; #22 daemon prio=9 os_prio=0 tid=0x000056473bf72800 nid=0x41 waiting on condition [0x0000000000000000]
&quot;DestroyJavaVM&quot; #21 prio=5 os_prio=0 tid=0x000056473bcd1800 nid=0x8 waiting on condition [0x0000000000000000]
&quot;qtp791452441-19-acceptor-0@27b0949f-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #19 prio=3 os_prio=0 tid=0x000056473bf75000 nid=0x24 runnable [0x00007fefe4b33000]
&quot;qtp791452441-17&quot; #17 prio=5 os_prio=0 tid=0x000056473bc2d800 nid=0x22 runnable [0x00007fefe8160000]
&quot;qtp791452441-16&quot; #16 prio=5 os_prio=0 tid=0x000056473bc2b000 nid=0x21 runnable [0x00007fefe8261000]
&quot;qtp791452441-15-lowPrioritySelector&quot; #15 prio=1 os_prio=0 tid=0x000056473bc29000 nid=0x20 waiting for monitor entry [0x00007fefe8363000]
&quot;qtp791452441-14-lowPrioritySelector&quot; #14 prio=1 os_prio=0 tid=0x000056473bc8c000 nid=0x1f waiting for monitor entry [0x00007fefe8464000]
&quot;qtp791452441-13-lowPrioritySelector&quot; #13 prio=1 os_prio=0 tid=0x000056473bc8a000 nid=0x1e waiting for monitor entry [0x00007fefe8565000]
&quot;qtp791452441-12-lowPrioritySelector&quot; #12 prio=1 os_prio=0 tid=0x000056473bc86800 nid=0x1d waiting for monitor entry [0x00007fefe8666000]
&quot;qtp791452441-11&quot; #11 prio=5 os_prio=0 tid=0x000056473bd8a800 nid=0x1c runnable [0x00007fefe8766000]
&quot;qtp791452441-10&quot; #10 prio=5 os_prio=0 tid=0x000056473bd84800 nid=0x1b runnable [0x00007fefe8867000]
&quot;Service Thread&quot; #9 daemon prio=9 os_prio=0 tid=0x000056473bc63800 nid=0x19 runnable [0x0000000000000000]
&quot;C1 CompilerThread3&quot; #8 daemon prio=9 os_prio=0 tid=0x000056473bc14000 nid=0x18 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread2&quot; #7 daemon prio=9 os_prio=0 tid=0x000056473bbf9000 nid=0x17 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x000056473bbea000 nid=0x16 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x000056473bbe7000 nid=0x15 waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x000056473bbe4800 nid=0x14 runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x000056473bbb5000 nid=0x13 in Object.wait() [0x00007fefe92cb000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x000056473bbb2000 nid=0x12 in Object.wait() [0x00007fefe93cc000]
&quot;VM Thread&quot; os_prio=0 tid=0x000056473bba8000 nid=0x11 runnable 
&quot;GC task thread#0 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f0000 nid=0x9 runnable 
&quot;GC task thread#1 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f2000 nid=0xa runnable 
&quot;GC task thread#2 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f3800 nid=0xb runnable 
&quot;GC task thread#3 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f5800 nid=0xc runnable 
&quot;GC task thread#4 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f7000 nid=0xd runnable 
&quot;GC task thread#5 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9f9000 nid=0xe runnable 
&quot;GC task thread#6 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9fa800 nid=0xf runnable 
&quot;GC task thread#7 (ParallelGC)&quot; os_prio=0 tid=0x000056473b9fc800 nid=0x10 runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x000056473bc59800 nid=0x1a waiting on condition

##
# Joyent Triton run
##
# Run second version of our container
eval &quot;$(triton env)&quot;
docker run -d -m 128m --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:2
# List the threads running
docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
&quot;qtp791452441-44&quot; #44 prio=5 os_prio=0 tid=0x000000000215e000 nid=0x12de4 runnable [0x00007fffe51f7000]
&quot;qtp791452441-43&quot; #43 prio=5 os_prio=0 tid=0x0000000000262000 nid=0x12aa4 waiting for monitor entry [0x00007fffe52fa000]
&quot;qtp791452441-42&quot; #42 prio=5 os_prio=0 tid=0x000000000068a000 nid=0x11808 waiting on condition [0x00007fffe7c7a000]
&quot;Scheduler-1896277646&quot; #41 prio=5 os_prio=0 tid=0x0000000000145000 nid=0x1176f waiting on condition [0x00007fffe4e34000]
&quot;Attach Listener&quot; #39 daemon prio=9 os_prio=0 tid=0x0000000000717800 nid=0x116e2 waiting on condition [0x0000000000000000]
&quot;DestroyJavaVM&quot; #33 prio=5 os_prio=0 tid=0x0000000000716000 nid=0x10796 waiting on condition [0x0000000000000000]
&quot;qtp791452441-32-acceptor-3@6dbc83d8-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #32 prio=3 os_prio=0 tid=0x0000000000714800 nid=0x1082a runnable [0x00007fffe5cff000]
&quot;qtp791452441-31-acceptor-2@1ac08473-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #31 prio=3 os_prio=0 tid=0x0000000000713000 nid=0x10829 waiting for monitor entry [0x00007fffe6000000]
&quot;qtp791452441-30-acceptor-1@34228b2c-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #30 prio=3 os_prio=0 tid=0x000000000070d800 nid=0x10828 waiting for monitor entry [0x00007fffe67fe000]
&quot;qtp791452441-29-acceptor-0@467e71fc-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #29 prio=3 os_prio=0 tid=0x000000000070b000 nid=0x10827 waiting for monitor entry [0x00007fffe6f72000]
&quot;qtp791452441-28-lowPrioritySelector&quot; #28 prio=1 os_prio=0 tid=0x0000000000695800 nid=0x10818 runnable [0x00007fffe72b3000]
&quot;qtp791452441-27&quot; #27 prio=5 os_prio=0 tid=0x000000000068d800 nid=0x10816 waiting on condition [0x00007fffe75f6000]
&quot;qtp791452441-26-lowPrioritySelector&quot; #26 prio=1 os_prio=0 tid=0x000000000068b800 nid=0x10815 runnable [0x00007fffe7937000]
&quot;qtp791452441-24-lowPrioritySelector&quot; #24 prio=1 os_prio=0 tid=0x0000000000687800 nid=0x10812 waiting for monitor entry [0x00007fffe7fbc000]
&quot;qtp791452441-23&quot; #23 prio=5 os_prio=0 tid=0x0000000000685800 nid=0x10810 waiting for monitor entry [0x00007fffe82fe000]
&quot;qtp791452441-22-lowPrioritySelector&quot; #22 prio=1 os_prio=0 tid=0x0000000000683800 nid=0x1080f waiting for monitor entry [0x00007fffe85ff000]
&quot;qtp791452441-21&quot; #21 prio=5 os_prio=0 tid=0x000000000067d000 nid=0x1080e runnable [0x00007fffe8b1d000]
&quot;Service Thread&quot; #20 daemon prio=9 os_prio=0 tid=0x00000000001ee800 nid=0x107c5 runnable [0x0000000000000000]
&quot;C1 CompilerThread14&quot; #19 daemon prio=9 os_prio=0 tid=0x00000000001e1800 nid=0x107c3 waiting on condition [0x0000000000000000]
&quot;C1 CompilerThread13&quot; #18 daemon prio=9 os_prio=0 tid=0x00000000001d7000 nid=0x107c1 waiting on condition [0x0000000000000000]
&quot;C1 CompilerThread12&quot; #17 daemon prio=9 os_prio=0 tid=0x00000000001d4000 nid=0x107bf waiting on condition [0x0000000000000000]
&quot;C1 CompilerThread11&quot; #16 daemon prio=9 os_prio=0 tid=0x00000000001b7800 nid=0x107bd waiting on condition [0x0000000000000000]
&quot;C1 CompilerThread10&quot; #15 daemon prio=9 os_prio=0 tid=0x00000000001ad800 nid=0x107bc waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread9&quot; #14 daemon prio=9 os_prio=0 tid=0x00000000001a2000 nid=0x107bb waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread8&quot; #13 daemon prio=9 os_prio=0 tid=0x0000000000197800 nid=0x107b9 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread7&quot; #12 daemon prio=9 os_prio=0 tid=0x0000000000172000 nid=0x107b8 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread6&quot; #11 daemon prio=9 os_prio=0 tid=0x0000000000186800 nid=0x107b7 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread5&quot; #10 daemon prio=9 os_prio=0 tid=0x000000000017c000 nid=0x107b6 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread4&quot; #9 daemon prio=9 os_prio=0 tid=0x0000000000165800 nid=0x107b5 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread3&quot; #8 daemon prio=9 os_prio=0 tid=0x000000000010f000 nid=0x107b3 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread2&quot; #7 daemon prio=9 os_prio=0 tid=0x0000000000104800 nid=0x107b2 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x00000000000f5000 nid=0x107b1 waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x00000000000f2800 nid=0x107b0 waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x00000000000f0800 nid=0x107af runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x00000000000c1000 nid=0x107a3 in Object.wait() [0x00007ffffd5fe000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x00000000000be000 nid=0x107a1 in Object.wait() [0x00007ffffe9fe000]
&quot;VM Thread&quot; os_prio=0 tid=0x00000000000b4000 nid=0x1079d runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x00000000001f3800 nid=0x107c6 waiting on condition 
</code></pre></noscript><br />
<div id="attachment_3549" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en.jpeg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3549" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en-1024x707.jpeg" alt="Triton isn`t a fun guy!" width="700" height="483" class="size-large wp-image-3549" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en-1024x707.jpeg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en-300x207.jpeg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en-768x530.jpeg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/cores-en.jpeg 1400w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3549" class="wp-caption-text">Triton isn`t a fun guy!</p></div><br />
Howly! More than 30 threads are running. On my computer the regular Docker container has 8 `GC task thread`s, and 4 `CompilerThread`s. On Triton there are 15! The JVM saw a lot of CPU cores and created many threads to take advantage of it. However, our container is restricted to 0.065 cores. Those many threads won`t help. Of course, we can configure this:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=version3.Dockerfile"></script><noscript><pre><code class="language-dockerfile dockerfile">FROM openjdk:8u121-jdk-alpine

# Assume already compiled for now
COPY target/scala-2.12/useless-demo-service.jar /app/useless-demo-service.jar

# Defaults for a tiny container
ENV MEMORY=&quot;64m&quot; \
    CPUS=1

EXPOSE 8080

CMD java -Xmx$MEMORY -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=&quot;kill -9 %p&quot; \
    -XX:CICompilerCount=&quot;$(($CPUS&gt;2?$CPUS:2))&quot; -XX:+UseSerialGC \
    -jar /app/useless-demo-service.jar</code></pre></noscript><br />
In this really small container the `ParallelGC` is not really needed and we can use the `SerialGC`. In case you use a bit larger container, you can use `-XX:-XX:+ParallelGCThreads=$CPU` for `ParallelGC`. Or `-XX:G1ConcRefinementThreads=$CPU` in case you use `-XX:+UseG1GC`.<br />
And we can use `-XX:CICompilerCount=$CPU` to reduce the compiler threads. However, it needs to be at least 2. </p>
<h2>Still Many Threads</h2>
<p>We still have many &#8216;acceptor&#8217; and &#8216;selector&#8217; threads. On Triton we&#8217;ve 4 acceptor and 4 selector threads:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=inspect-threads-2nd.sh"></script><noscript><pre><code class="language-shell shell">##
# Local docker run 
##
# Run third version of our container
sudo docker run -d -m 128m --cpus 0.065 --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:3
# List the threads running
sudo docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
&quot;Attach Listener&quot; #20 daemon prio=9 os_prio=0 tid=0x0000564e7cd17000 nid=0x37 waiting on condition [0x0000000000000000]
&quot;qtp791452441-19&quot; #19 prio=5 os_prio=0 tid=0x0000564e7cd15000 nid=0x36 waiting on condition [0x00007fdcc863f000]
&quot;qtp791452441-17-acceptor-0@77fe3be4-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #17 prio=3 os_prio=0 tid=0x0000564e7cc25000 nid=0x34 runnable [0x00007fdcc8841000]
&quot;DestroyJavaVM&quot; #16 prio=5 os_prio=0 tid=0x0000564e7c922800 nid=0x8 waiting on condition [0x0000000000000000]
&quot;qtp791452441-15-lowPrioritySelector&quot; #15 prio=1 os_prio=0 tid=0x0000564e7ce14000 nid=0x31 waiting for monitor entry [0x00007fdccbd6e000]
&quot;qtp791452441-14&quot; #14 prio=5 os_prio=0 tid=0x0000564e7ce12000 nid=0x30 runnable [0x00007fdccbe6e000]
&quot;qtp791452441-13-lowPrioritySelector&quot; #13 prio=1 os_prio=0 tid=0x0000564e7ce0f800 nid=0x2f waiting for monitor entry [0x00007fdccbf70000]
&quot;qtp791452441-12&quot; #12 prio=5 os_prio=0 tid=0x0000564e7ce0e000 nid=0x2e runnable [0x00007fdccc070000]
&quot;qtp791452441-11-lowPrioritySelector&quot; #11 prio=1 os_prio=0 tid=0x0000564e7ce0c000 nid=0x2d waiting for monitor entry [0x00007fdccc172000]
&quot;qtp791452441-10-lowPrioritySelector&quot; #10 prio=1 os_prio=0 tid=0x0000564e7ce0a000 nid=0x2b waiting for monitor entry [0x00007fdccc273000]
&quot;qtp791452441-9&quot; #9 prio=5 os_prio=0 tid=0x0000564e7ce07800 nid=0x2a runnable [0x00007fdccc373000]
&quot;qtp791452441-8&quot; #8 prio=5 os_prio=0 tid=0x0000564e7ce01000 nid=0x29 runnable [0x00007fdccc474000]
&quot;Service Thread&quot; #7 daemon prio=9 os_prio=0 tid=0x0000564e7c8c2800 nid=0xf runnable [0x0000000000000000]
&quot;C1 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x0000564e7c8b7800 nid=0xe waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x0000564e7c8ac800 nid=0xd waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x0000564e7c8aa800 nid=0xc runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x0000564e7c87d800 nid=0xb in Object.wait() [0x00007fdccccd4000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x0000564e7c873000 nid=0xa in Object.wait() [0x00007fdcccdd5000]
&quot;VM Thread&quot; os_prio=0 tid=0x0000564e7c869000 nid=0x9 runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x0000564e7c8c5800 nid=0x10 waiting on condition 


##
# Joyent Triton run
##
# Run third version of our container
eval &quot;$(triton env)&quot;
docker run -d -m 128m --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:3
# List the threads running
docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
&quot;Attach Listener&quot; #23 daemon prio=9 os_prio=0 tid=0x000000000028c000 nid=0x732a waiting on condition [0x0000000000000000]
&quot;qtp791452441-22&quot; #22 prio=5 os_prio=0 tid=0x00000000006eb000 nid=0x7178 waiting on condition [0x00007fffe81fe000]
&quot;qtp791452441-21-acceptor-3@161ab1a8-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #21 prio=3 os_prio=0 tid=0x00000000006ea000 nid=0x7177 waiting for monitor entry [0x00007fffe84ff000]
&quot;DestroyJavaVM&quot; #20 prio=5 os_prio=0 tid=0x00000000001df000 nid=0x7109 waiting on condition [0x0000000000000000]
&quot;qtp791452441-19-acceptor-2@70b4bcd9-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #19 prio=3 os_prio=0 tid=0x00000000006e7000 nid=0x7175 waiting for monitor entry [0x00007fffe8800000]
&quot;qtp791452441-18-acceptor-1@57033676-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #18 prio=3 os_prio=0 tid=0x0000000000747800 nid=0x7174 waiting for monitor entry [0x00007fffe97f6000]
&quot;qtp791452441-17-acceptor-0@67e0dd84-ServerConnector@512ddf17{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}&quot; #17 prio=3 os_prio=0 tid=0x00000000006e4800 nid=0x7173 runnable [0x00007fffe8ffe000]
&quot;qtp791452441-15-lowPrioritySelector&quot; #15 prio=1 os_prio=0 tid=0x000000000066b000 nid=0x7159 waiting for monitor entry [0x00007fffe9af7000]
&quot;qtp791452441-14&quot; #14 prio=5 os_prio=0 tid=0x000000000066c800 nid=0x7157 runnable [0x00007fffe9df7000]
&quot;qtp791452441-13-lowPrioritySelector&quot; #13 prio=1 os_prio=0 tid=0x0000000000668800 nid=0x7156 waiting for monitor entry [0x00007fffea0f9000]
&quot;qtp791452441-12&quot; #12 prio=5 os_prio=0 tid=0x0000000000666800 nid=0x7155 runnable [0x00007fffea3f9000]
&quot;qtp791452441-11&quot; #11 prio=5 os_prio=0 tid=0x0000000000664800 nid=0x7154 runnable [0x00007fffea6fa000]
&quot;qtp791452441-10-lowPrioritySelector&quot; #10 prio=1 os_prio=0 tid=0x0000000000662800 nid=0x7153 waiting for monitor entry [0x00007fffea9fc000]
&quot;qtp791452441-9&quot; #9 prio=5 os_prio=0 tid=0x0000000000660800 nid=0x7152 runnable [0x00007fffeacfc000]
&quot;qtp791452441-8-lowPrioritySelector&quot; #8 prio=1 os_prio=0 tid=0x0000000000659800 nid=0x7151 waiting for monitor entry [0x00007fffeaffe000]
&quot;Service Thread&quot; #7 daemon prio=9 os_prio=0 tid=0x0000000000130800 nid=0x7120 runnable [0x0000000000000000]
&quot;C1 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x0000000000104000 nid=0x711e waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x00000000000f2800 nid=0x711d waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x00000000000f0800 nid=0x711c runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x00000000000c1000 nid=0x7115 in Object.wait() [0x00007ffffd5fe000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x00000000000be000 nid=0x7113 in Object.wait() [0x00007ffffe9fe000]
&quot;VM Thread&quot; os_prio=0 tid=0x00000000000b4000 nid=0x710f runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x0000000000128800 nid=0x7121 waiting on condition 

</code></pre></noscript><br />
Those threads are created by the web server, so you have to configure the web server you are using. In this example Jetty is used, and we configure it via simple Java properties:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=DemoService.scala"></script><noscript><pre><code class="language-scala scala">// Version 1 did just start Jetty
// val server = new Server(8080)
// It creates many acceptors, selectors and threads on big machines, even when running in small container
// So, let&#039;s explicitly configure it.
val minThreads = System.getProperty(&quot;jetty.min-threads&quot;, &quot;8&quot;).toInt
val maxThreads = System.getProperty(&quot;jetty.max-threads&quot;, &quot;200&quot;).toInt
var threadPool = new QueuedThreadPool(minThreads, maxThreads)

val server = new Server(threadPool)
val acceptorCount = System.getProperty(&quot;jetty.acceptor-threads&quot;, &quot;-1&quot;).toInt
val selectorCount = System.getProperty(&quot;jetty.selector-threads&quot;, &quot;-1&quot;).toInt
server.setConnectors(Array(new ServerConnector(server, acceptorCount, selectorCount)))

server.setHandler(new OurHandling)
server.start()</code></pre></noscript><br />
And also change the Docker file:<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=version4.Dockerfile"></script><noscript><pre><code class="language-dockerfile dockerfile">FROM openjdk:8u121-jdk-alpine

# Assume already compiled for now
COPY target/scala-2.12/useless-demo-service.jar /app/useless-demo-service.jar

# Defaults for a tiny container
ENV MEMORY=&quot;64m&quot; \
    CPUS=1\
    ACCEPTORS=1 \
    SELECTORS=1\
    JETTY_MIN_THREADS=4 \
    JETTY_MAX_THREADS=20

EXPOSE 8080

CMD java -Xmx$MEMORY -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=&quot;kill -9 %p&quot; \
    -XX:CICompilerCount=&quot;$(($CPUS&gt;2?$CPUS:2))&quot; -XX:+UseSerialGC \
    -Djetty.acceptor-threads=$ACCEPTORS \
    -Djetty.selector-threads=$SELECTORS \
    -Djetty.min-threads=$JETTY_MIN_THREADS \
    -Djetty.max-threads=$JETTY_MAX_THREADS \
    -jar /app/useless-demo-service.jar</code></pre></noscript><br />
And now, it starts to look fine, right?<br />
<script src="https://gist.github.com/e8d7809070bae3cf07d129e1774fae1c.js?file=inspect-threads-3rd.sh"></script><noscript><pre><code class="language-shell shell">##
# Local docker run 
##
# Run forth version of our container
sudo docker run -d -m 128m --cpus 0.065 --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:4
# List the threads running
sudo docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
&quot;DestroyJavaVM&quot; #13 prio=5 os_prio=0 tid=0x000055927f487000 nid=0x8 waiting on condition [0x0000000000000000]
&quot;qtp2096171631-12-acceptor-0@38ffe3b-ServerConnector@457e2f02{HTTP/1.1,[http/1.1]}{0.0.0.0:45611}&quot; #12 prio=3 os_prio=0 tid=0x000055927f4b9800 nid=0x30 runnable [0x00007ff4bbd45000]
&quot;qtp2096171631-11-lowPrioritySelector&quot; #11 prio=1 os_prio=0 tid=0x000055927f4b4800 nid=0x2f waiting for monitor entry [0x00007ff4bbe46000]
&quot;qtp2096171631-10&quot; #10 prio=5 os_prio=0 tid=0x000055927f4b3000 nid=0x2e runnable [0x00007ff4bbf46000]
&quot;qtp2096171631-9&quot; #9 prio=5 os_prio=0 tid=0x000055927ec6d800 nid=0x2d waiting on condition [0x00007ff4bc048000]
&quot;Attach Listener&quot; #8 daemon prio=9 os_prio=0 tid=0x000055927f7f0000 nid=0x2c waiting on condition [0x0000000000000000]
&quot;Service Thread&quot; #7 daemon prio=9 os_prio=0 tid=0x000055927ea74000 nid=0xf runnable [0x0000000000000000]
&quot;C1 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x000055927ea59000 nid=0xe waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x000055927ea56800 nid=0xd waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x000055927ea54800 nid=0xc runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x000055927ea24000 nid=0xb in Object.wait() [0x00007ff4bc9a7000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x000055927ea19800 nid=0xa in Object.wait() [0x00007ff4bcaa8000]
&quot;VM Thread&quot; os_prio=0 tid=0x000055927ea0f000 nid=0x9 runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x000055927ea71800 nid=0x10 waiting on condition 


##
# Joyent Triton run
##
# Run forth version of our container
eval &quot;$(triton env)&quot;
docker run -d -m 128m --name=jvm-on-small-container -p 8080:8080 gamlerhart/blog-jvm-on-small-containers:4
# List the threads running
docker exec jvm-on-small-container sh -c &#039;jstack `pgrep java`&#039; | grep os_prio 
Attach Listener&quot; #13 daemon prio=9 os_prio=0 tid=0x0000000000a5f000 nid=0x91c2 waiting on condition [0x0000000000000000]
&quot;DestroyJavaVM&quot; #12 prio=5 os_prio=0 tid=0x0000000000f3f800 nid=0x8e75 waiting on condition [0x0000000000000000]
&quot;qtp2096171631-11-acceptor-0@5230b90f-ServerConnector@5cf74d39{HTTP/1.1,[http/1.1]}{0.0.0.0:54428}&quot; #11 prio=3 os_prio=0 tid=0x0000000001075000 nid=0x8ead runnable [0x00007fffea6fb000]
&quot;qtp2096171631-10-lowPrioritySelector&quot; #10 prio=1 os_prio=0 tid=0x0000000001073000 nid=0x8eac waiting for monitor entry [0x00007fffea9fc000]
&quot;qtp2096171631-9&quot; #9 prio=5 os_prio=0 tid=0x0000000001070800 nid=0x8eab waiting on condition [0x00007fffeacfd000]
&quot;qtp2096171631-8&quot; #8 prio=5 os_prio=0 tid=0x0000000001070000 nid=0x8eaa runnable [0x00007fffeaffd000]
&quot;Service Thread&quot; #7 daemon prio=9 os_prio=0 tid=0x0000000000179000 nid=0x8e81 runnable [0x0000000000000000]
&quot;C1 CompilerThread1&quot; #6 daemon prio=9 os_prio=0 tid=0x00000000000f5000 nid=0x8e7f waiting on condition [0x0000000000000000]
&quot;C2 CompilerThread0&quot; #5 daemon prio=9 os_prio=0 tid=0x00000000000f3000 nid=0x8e7e waiting on condition [0x0000000000000000]
&quot;Signal Dispatcher&quot; #4 daemon prio=9 os_prio=0 tid=0x00000000000f1000 nid=0x8e7d runnable [0x0000000000000000]
&quot;Finalizer&quot; #3 daemon prio=8 os_prio=0 tid=0x00000000000c4800 nid=0x8e78 in Object.wait() [0x00007ffffd5fe000]
&quot;Reference Handler&quot; #2 daemon prio=10 os_prio=0 tid=0x00000000000be800 nid=0x8e77 in Object.wait() [0x00007ffffe9fe000]
&quot;VM Thread&quot; os_prio=0 tid=0x00000000000b4000 nid=0x8e76 runnable 
&quot;VM Periodic Task Thread&quot; os_prio=0 tid=0x0000000000117800 nid=0x8e82 waiting on condition 

</code></pre></noscript></p>
<h2>Be Still Carefull of Many Threads</h2>
<p>Our example web app now runs fine. But keep an eye on the thread count. Other Java/programming language library might create a thread pool and many threads. However, you can configure these libraries too. </p>
<h2>Update 21th June, 2017</h2>
<p>Well, first the <a href="https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits">OpenJDK team is improving the situation</a>. As of JDK 8u131, the JVM does limit the CPU&#8217;s in Docker. And with the experimental flags &#8216;-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap&#8217; it does limit the memory.</p>
<p>Also, Matt Rasband has a <a href="https://medium.com/@matt_rasband/dockerizing-a-spring-boot-application-6ec9b9b41faf">good blog post</a> on how to estimate the memory usage of the JVM and set the flags properly.</p>
<p>Have fun running the JVM in a tiny container =)</p><p>The post <a href="https://www.gamlor.info/wordpress/2017/04/deploying-jvm-in-tiny-containers-be-carefull/">Deploying JVM in tiny containers, be carefull!</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Transfer Files via Web: curl https://rohrli.gamlor.info</title>
		<link>https://www.gamlor.info/wordpress/2017/04/transfer-files-via-web-curl-rohrli-gamlor-info/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Sun, 16 Apr 2017 12:53:51 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[rohrli]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">https://www.gamlor.info/wordpress/?p=3451</guid>

					<description><![CDATA[<p>Did you ever have this situation: You&#8217;re SSH&#8217;ed into a box. Or worse, you&#8217;re on some corporate *hmmkkmm slow* VPN, over which you SSH&#8217;ed into a box. Or worse, corporate&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2017/04/transfer-files-via-web-curl-rohrli-gamlor-info/">Transfer Files via Web: curl https://rohrli.gamlor.info</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Did you ever have this situation: You&#8217;re SSH&#8217;ed into a box. Or worse, you&#8217;re on some corporate *hmmkkmm slow* VPN, over which you SSH&#8217;ed into a box. Or worse, corporate VPN, use RDP to some Windows server, on that opening some tool thing which has a console to a virtual machine? And you need to want to transfer some 10&#8217;s of megs or more debug data out?<br />
If you&#8217;re lucky, you get a slow transfer going. If you&#8217;ve bad luck, there no sane way to directly transfer the data.<br />
Then you waste time trying to use a &#8216;send files via web&#8217; service&#8230;oh god. And in the end you might move data via some server you control =(.</p>
<h2>Why can&#8217;t I just user CURL? </h2>
<p>Yes, why can&#8217;t I just use use CURL. Like, I &#8216;upload&#8217; the data via curl, and download it at the other end. Like a simple pipe. No signing up, sending emails which links to the &#8216;large file&#8217;, no need for a browser.</p>
<p>I basically just wanted something like.</p>
<pre>
gamlor@machine-a: cat my-data | curl
gamlor@machine-b: curl &gt; my-data
</pre>
<p>Nothing more. It does need to store it. Just a file transfer!<br />
<div id="attachment_3461" style="width: 810px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3461" src="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli.jpg" alt="File Transfer Trouble" width="800" height="2145" class="size-full wp-image-3461" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli.jpg 800w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli-112x300.jpg 112w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli-768x2059.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2017/04/why-rohrli-382x1024.jpg 382w" sizes="(max-width: 800px) 100vw, 800px" /></a><p id="caption-attachment-3461" class="wp-caption-text">File Transfer Trouble</p></div></p>
<h2>curl https://rohrli.gamlor.info</h2>
<p>So I built it for myself =). And here it is: Röhrli, pipe files via web: <a href="https://rohrli.gamlor.info"></a>.</p>
<p>You start by pointing CURL at it. Do not miss the S in httpS =).  It will then give you a guide. A example:</p>
<pre>
curl https://rohrli.gamlor.info

>    Röhrli: Pipe your files via Web.
> ⁼
>    cURL guide:
>
>    Basics:
>    - Shows this help text. (or web page in a browser)
>        curl https://rohrli.gamlor.info
>    - Pipe a file to röhrli. It will respond with an URL:
>        cat my-file | curl -N --data-binary @- https://rohrli.gamlor.info
>    - Gzip if needed:
>        cat my-file | gzip | curl -N --data-binary @- https://rohrli.gamlor.info
>    - The request will give you an URL. Then read from it on another place:
>        curl {the-url-returned} > my-file
>
>    Any question? Email: roman.stoffel@gamlor.info. Twitter: @gamlerhart
</pre>
<p>Then you pipe your file / data to curl. As told by the instruction. After that, you&#8217;re receive instructions how do download the data.<br />
Do not stop CURL. Röhrli does not store the file on the server. It just transfers data from the uploader to the downloader.</p>
<pre>
echo data > test-file.txt
cat test-file.txt | curl -N --data-binary @- https://rohrli.gamlor.info

>    You're pipe was created at https://rohrli.gamlor.info/vykkev-xizras-puzwyq-vauveq
>
>    Download it with:
>    - curl https://rohrli.gamlor.info/vykkev-xizras-puzwyq-vauveq > my-file.txt
>    If you uploaded gzipped, decompress:
>    - curl https://rohrli.gamlor.info/vykkev-xizras-puzwyq-vauveq | gzip -d > my-file.txt
>
>    This pipe is streaming. No data is permanently stored on the server.
>    Do not quit (Ctrl-C/D) before the transfer is done.
>
>    Verify that the download is complete and correct with: sha1sum my-file.txt
>    
>    Start your download now. We're waiting for the download to start for 10 minutes
>    ......
</pre>
<p>As you see, you get a unique link. You now can download it =). You might want to double check the download with something like sha1sum.</p>
<pre>
curl https://rohrli.gamlor.info/vykkev-xizras-puzwyq-vauveq > my-file.txt

>    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
>                                    Dload  Upload   Total   Spent    Left  Speed
>    100     5  100     5    0     0      2      0  0:00:02  0:00:02 --:--:--     2
</pre>
<p>And you&#8217;re done!<br />
Up and downloading of course also work with a browser =).</p>
<p>That&#8217;s about it. If you find a bug or have wishes, let me know =)</p><p>The post <a href="https://www.gamlor.info/wordpress/2017/04/transfer-files-via-web-curl-rohrli-gamlor-info/">Transfer Files via Web: curl https://rohrli.gamlor.info</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Code Reloading in Clojure</title>
		<link>https://www.gamlor.info/wordpress/2016/08/code-reloading-in-clojure/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Sun, 07 Aug 2016 13:19:16 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[test-refresh]]></category>
		<guid isPermaLink="false">http://www.gamlor.info/wordpress/?p=3128</guid>

					<description><![CDATA[<p>I like quick feed back while I&#8217;m coding. Instead of &#8216;playing&#8217; computer in my head, let the code code run and see if it does what I expect it to&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2016/08/code-reloading-in-clojure/">Code Reloading in Clojure</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I like quick feed back while I&#8217;m coding. Instead of &#8216;playing&#8217; computer in my head, let the code code run and see if it does what I expect it to do. It&#8217;s one of the reasons enjoy working in a test first workflow and having a test friendly code base.<br />
<div id="attachment_3344" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3344" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_-737x1024.jpg" alt="Just changing curtains color" width="700" height="973" class="size-large wp-image-3344" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_-737x1024.jpg 737w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_-216x300.jpg 216w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_-768x1067.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/base.house_.jpg 1309w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3344" class="wp-caption-text">Just changing curtains color</p></div></p>
<p>Anyway, some things are just easier to &#8216;tweak&#8217; visually and experiment. For example when working on a GUI code or some REST output. So, I want that changes are immediately available. In Clojure there are different, ready to use solutions to do code reloading. Like <a href="https://github.com/bhauman/lein-figwheel">Figweel </a>for Clojurescript and web front-ends. </p>
<p>Here I am not going into Figweel and many other solutions. Instead I&#8217;m using Clojure facilities, without any special tools. I also take a look at on code reloader: <a href="https://github.com/jakemcc/lein-test-refresh">test-referesh</a></p>
<h2>Basics: Reload with use</h2>
<p>Assuming we have some piece Clojure code. Like this:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=my_friendly_emailer.clj"></script><noscript><pre><code class="language-clojure clojure">(ns my-friendly-emailer
  (:require [clojure.string :as str]))

(defn create-text
  &quot;Creates a super friendly email text&quot;
  [user]
  (str
    &quot;Hello &quot; (:fullname user) &quot;\n&quot;
    &quot;You like &quot; (str/join &quot;,&quot; (:likes user))))

(defn create-email
  &quot;Creates an email, ready to send&quot;
  [user]
  {:to   (:email user)
   :body (create-text user)})

(def example-user
  {
   :fullname &quot;Jill Awesome&quot;
   :username &quot;jill&quot;
   :email    &quot;jill@test.local&quot;
   :likes    [&quot;Sports&quot;, &quot;Movies&quot;, &quot;Cars&quot;]
   })</code></pre></noscript><br />
Now, we want to &#8216;tune&#8217; the email and make it actually a friendly email. So you include it into your REPL and evaluate the result:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=initial-use.clj"></script><noscript><pre><code class="language-clojure clojure">(use &#039;my-friendly-emailer)
(create-email example-user)</code></pre></noscript><br />
Now you did some changes. But when you use the `create-emails` function again, it still prints out the old result. You don&#8217;t want to restart, but just reload it and keep going. Well, the &#8216;use&#8217; macro already has reloading built in. Load the namespace of the file with the <code>:reload</code> flag:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=realod-with-use.clj"></script><noscript><pre><code class="language-clojure clojure">(use &#039;my-friendly-emailer :reload)
(create-email example-user)</code></pre></noscript><br />
That&#8217;s it. Clojure will reload the code in the namespace for you. Nothing else to do.</p>
<h2>Reload more, :reload-all</h2>
<p>Maybe the change you made is actually in some dependency. Assume we have this function in another namespace, which refers the the friendly email code:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=uses_emails.clj"></script><noscript><pre><code class="language-clojure clojure"> (ns uses-emails
   (:require [my-friendly-emailer :as mail]))

 (defn preview-email-example []
   (doseq [email (mail/create-email mail/example-user)]
     (println (:body email))))
</code></pre></noscript><br />
When you use the &#8216;preview-email-examples&#8217; function, you might notice that reloading with `(use &#8216;uses-emails :reload)`, it will not include changes made to the my-friendly-emailer.clj file. Use the :reload-all flag. It also reloads any dependencies:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=reload-dependency.clj"></script><noscript><pre><code class="language-clojure clojure">(use &#039;uses-emails :reload-all)
(preview-email-example)</code></pre></noscript></p>
<div id="attachment_3349" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3349" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj-1024x810.jpg" alt="Yes, please just change the curtains." width="700" height="554" class="size-large wp-image-3349" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj-1024x810.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj-300x237.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj-768x607.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/with-clj.jpg 1200w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3349" class="wp-caption-text">Yes, please just change the curtains.</p></div>
<h2>Automate Reloading, Example REST Server</h2>
<p>You can use the &#8216;use&#8217; primitive easily to create your own reload mechanism. This is useful, when you use Clojure in some embedded scenario or existing of the shelf reloaders do not work.. Let&#8217;s extend the given email example to a web service:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=our-web-server.clj"></script><noscript><pre><code class="language-clojure clojure">(ns our-web-server
     (:require
       [my-friendly-emailer :as mail]
       [ring.adapter.jetty :as jetty]
       [clojure.data.json :as json]))

(comment
  &quot;included dependencies, like in lein:&quot;
  [[org.clojure/data.json &quot;0.2.6&quot;]
   [ring/ring-core &quot;1.5.0&quot;]
   [ring/ring-jetty-adapter &quot;1.5.0&quot;]]
  )

(defn handler
  &quot;Most boring handler. Just returns our example emails as JSON&quot;
  [request]
  {:status  200
   :headers {&quot;Content-Type&quot; &quot;application/json&quot;}
   :body    (json/write-str (mail/create-email mail/example-user))})

(defn start-server []
  (jetty/run-jetty handler {:port 3000 :join? false})
  )

(def running-server (start-server))</code></pre></noscript><br />
This web server is pretty annoying. If we change anything in the email template code, we have to restart it. Wouldn&#8217;t it be nice if changes are visible on the next browser refresh. Well, we can hack that our self. We add a developer flag. When that is set, we just go and reload our app&#8217;s main namespace.<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=adhoc-reloading.clj"></script><noscript><pre><code class="language-clojure clojure">; Allow changing in REPL.
; In a real app this could be admin functionality / more advanced toggle
(def reload-enabled
  (atom false))

(defn handler
  &quot;Most boring handler. Just returns our example email as JSON&quot;
  [request]
  ; When reload is enabled, then we do a full reload
  (when @reload-enabled
    (use &#039;my-friendly-emailer :reload-all))
  {:status  200
   :headers {&quot;Content-Type&quot; &quot;application/json&quot;}
   :body    (json/write-str (mail/create-email mail/example-user))})</code></pre></noscript><br />
Then we enable it. In this example just in via the REPL. In a real app the toggle mechanism can be more advanced<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=enable-reload.clj"></script><noscript><pre><code class="language-clojure clojure">(use &#039;our-web-server)
(reset! reload-enabled true)</code></pre></noscript><br />
Of course, for <a href="https://github.com/ring-clojure/ring">Ring</a> there is already a reload library (probably even more than one). For example the <a href="https://github.com/ring-clojure/ring/wiki/Reloading">reload wrapper</a> from ring-devel library.</p>
<h2>Using test-refresh</h2>
<p>So far we used core Clojure functionality. Based on that you certainly can go deeper and create more elaborate reloading schemes. One of such is <a href="https://github.com/jakemcc/lein-test-refresh">test-refresh</a>, a <a href="http://leiningen.org/">Leiningen</a> plugin. I just add it to my ~/.lein/profiles.clj, so that it is available in any project I touch:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=home-dot-lein-profiles.clj"></script><noscript><pre><code class="language-clojure clojure">; In  ~/.lein/profiles.clj
{:user {:plugins [[com.jakemccrary/lein-test-refresh &quot;0.16.0&quot;]]}}
</code></pre></noscript><br />
This gives the `lein test-refresh` command. That command will run the test suite. The cool thing now is, that it will rerun tests which are affected by a change. So you get immediate feed back if your edit just broke something. Even better, you just can experiment around, while test-refresh reloads the code, giving you always feed back. </p>
<div id="attachment_3352" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3352" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh-1024x585.jpg" alt="Immediate feedback." width="700" height="400" class="size-large wp-image-3352" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh-1024x585.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh-300x172.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh-768x439.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/test-refrsh.jpg 1200w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3352" class="wp-caption-text">Immediate feedback.</p></div>
<p>Here a screen series to illustrate that. Or if you have time, checkout this video: <a href="https://www.youtube.com/watch?v=ZD8q3fMr5sE">Don`t settle for a REPL</a>.</p>
<p>When started, the tests are executed first:<br />
<a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/start-ok.jpg"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/start-ok.jpg" alt="First your tests are executed." width="880" height="580" class="aligncenter size-full wp-image-3335" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/start-ok.jpg 880w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/start-ok-300x198.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/start-ok-768x506.jpg 768w" sizes="(max-width: 880px) 100vw, 880px" /></a><br />
When editing, as soon as you save a file, all tests which depend on that change are executed again<br />
<a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/breakage.jpg"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/breakage.jpg" alt=" " width="897" height="719" class="aligncenter size-full wp-image-3336" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/breakage.jpg 897w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/breakage-300x240.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/breakage-768x616.jpg 768w" sizes="(max-width: 897px) 100vw, 897px" /></a><br />
Now, you also just can try code out right there. The results are shown immediatly. Like a free edit REPL:<br />
<a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/more-examples.jpg"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/more-examples.jpg" alt="more-examples" width="882" height="738" class="aligncenter size-full wp-image-3337" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/more-examples.jpg 882w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/more-examples-300x251.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/more-examples-768x643.jpg 768w" sizes="(max-width: 882px) 100vw, 882px" /></a><br />
That also allows you to monitor some high level end result, while changing the lower level functions:<br />
<a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/lower-level.jpg"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/lower-level.jpg" alt="lower-level" width="896" height="424" class="aligncenter size-full wp-image-3338" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/lower-level.jpg 896w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/lower-level-300x142.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/08/lower-level-768x363.jpg 768w" sizes="(max-width: 896px) 100vw, 896px" /></a></p>
<h2>Use test-refresh or your Test Server</h2>
<p>Well, you can also use test refresh to reload your server when files change. What I usually do put the server in a separate namespace, with no dependency to my core app. When the file and its dependencies does not change, test-refresh won`t reload it. This means that test refresh does not reload the actual server. Note that the test server exposes an atom for the actual request handler:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=test_server.clj"></script><noscript><pre><code class="language-clojure clojure">(ns test-server
  ; Only depends on Jetty / Ring.
  ; Since that won&#039;t change, it isn&#039;t reloaded by test refresh
  (:require [ring.adapter.jetty :as jetty]))

; This will be swapped out by the test setup
; That setup will have the actual app in the dependency list and therefore be reloaded by test-refresh
(def test-handler (atom (fn [request] {:status 503})))

(defn- call-latest-handler [request]
  (@test-handler request))

(println &quot;Starting test server&quot;)
(jetty/run-jetty call-latest-handler {:port 3000 :join? false})
</code></pre></noscript><br />
Then we add a &#8216;test setup&#8217; file. That one depends on our application. Since our application changes, and this file depends on it, it will be reloaded as soon as we change anything in our applicaiton. When reloaded, it will swap out the handler of the test server. So, if the app changes, test-reload will do it`s reload logic and we also will have the latest code running in the web server:<br />
<script src="https://gist.github.com/e217c3d5cfe32c0d9ed167abf711d3f8.js?file=my_test_app_setup.clj"></script><noscript><pre><code class="language-clojure clojure">(ns my-test-app-setup
  (:require
    [test-server :as server]
    [clojure.data.json :as json]
    ;Right here, we includ our app
    [my-friendly-emailer :as mail]))

; This namespace depends on our app.
; When the app is changed, this file will be reloaded too by test-refresh
; Then we just swap out the request handler of the test jetty server

; Everytime this file is loaded, just swap out the request handler with the current version of the code
(reset! server/test-handler
        (fn [request]
          ; Ok, you would put the entry of the app here =)
          {:status  200
           :headers {&quot;Content-Type&quot; &quot;application/json&quot;}
           :body    (json/write-str (mail/create-email mail/example-user))}))
</code></pre></noscript><br />
This can be done for other server types and setups. Is neat for places where there no pre made plugin or you need a very specific setup.</p>
<h2>Keep on reloading</h2>
<p>That`s it for today =). Happy reloading. ^.^</p><p>The post <a href="https://www.gamlor.info/wordpress/2016/08/code-reloading-in-clojure/">Code Reloading in Clojure</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Joyent&#8217;s Triton : /native, our friend!</title>
		<link>https://www.gamlor.info/wordpress/2016/07/joyents-triton-native-our-friend/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Fri, 29 Jul 2016 12:50:01 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[containers]]></category>
		<category><![CDATA[joyent]]></category>
		<category><![CDATA[triton]]></category>
		<guid isPermaLink="false">http://www.gamlor.info/wordpress/?p=3279</guid>

					<description><![CDATA[<p>We deployed our Docker container on Triton and everything works well. Suddenly, today there a issue. Our application is slow or stopped working. And in our container there is not&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2016/07/joyents-triton-native-our-friend/">Joyent’s Triton : /native, our friend!</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>We deployed our Docker container on Triton and everything works well. Suddenly, today there a issue. Our application is slow or stopped working. And in our container there is not debugging tool. So, what should we do?<br />
<div id="attachment_3313" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3313" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_-863x1024.jpg" alt="Rebooting is no solution" width="700" height="831" class="size-large wp-image-3313" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_-863x1024.jpg 863w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_-253x300.jpg 253w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_-768x911.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/rebooting.en_.jpg 1200w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3313" class="wp-caption-text">Rebooting is no solution</p></div></p>
<h2>Explore Triton&#8217;s Container a bit</h2>
<p>I started again a nginx container on Triton:<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=explore-start-ngnix.sh"></script><noscript><pre><code class="language-shell shell">#Switch to Triton
eval $(triton env)
# Start nginx on triton
docker run -d --name test -p 80 nginx</code></pre></noscript><br />
When the container has started, start a shell inside the container with &#8216;docker exec&#8217;. Then explore the file system a bit.<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=interactive-shell-on-container.sh"></script><noscript><pre><code class="language-shell shell">roman@minty ~ $ docker exec -ti test /bin/bash
root@ae35cee7759b:/# ls -l
</code></pre></noscript><br />
<div id="attachment_3254" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/native.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3254" class="size-medium wp-image-3254" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/native-300x195.jpg" alt="/native?" width="300" height="195" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/native-300x195.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/native.jpg 549w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3254" class="wp-caption-text">/native?</p></div><br />
What the hell is /native? Look a around a bit more. Maybe try to find popular unix tools in there? Aha! From `awk` to `zcat`, everything is there. So /native is another Unix? Right! /native is a window into Triton&#8217;s native operating system. And there are popular unix tools there.<br />
<div id="attachment_3259" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/explored.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3259" class="size-medium wp-image-3259" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/explored-300x228.jpg" alt="Explore!" width="300" height="228" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/explored-300x228.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/explored.jpg 561w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3259" class="wp-caption-text">Explore!</p></div><br />
<div id="attachment_3314" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3314" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_-1024x350.jpg" alt="At /native/ old unix tools live." width="700" height="239" class="size-large wp-image-3314" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_-1024x350.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_-300x103.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_-768x262.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/slash-native.en_.jpg 1200w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3314" class="wp-caption-text">At /native/ old unix tools live.</p></div></p>
<h2>Let&#8217;s use /native</h2>
<p>Now we know that /native exists so let&#8217;s use it. First let&#8217;s deploy a bad container. I&#8217;ve prepared a &#8216;bad container&#8217; example. The <a href="https://gist.github.com/gamlerhart/5582bce62cfea2ea4aad57956df2a7b5">code is here</a>. Let&#8217;s start that &#8216;gamlerhart/waste-io&#8217; container:<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=start-bad-container.sh"></script><noscript><pre><code class="language-shell shell">docker run -d --name waste-io-example gamlerhart/waste-io</code></pre></noscript><br />
This container has a issue. Let&#8217;s start finding out what the problem is. Again, we `docker exec` into the container. If we try to use `iostat`, nothing is there. However, we can use /native. Add /native to the PATH and we can use `iostat`.<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=iostat.sh"></script><noscript><pre><code class="language-shell shell">roman@minty ~ $ docker exec -ti waste-io-example /bin/bash
root@3bd53e4a7fe4:/# 
root@3bd53e4a7fe4:/# iostat -M 1
bash: iostat: command not found

#Oh...damn...iostat would tell us if our IO is sane.
#Ah.../native to the rescue
root@3bd53e4a7fe4:/# iostat -M 1
   tty      ramdisk1        sd0           sd1           sd2            cpu
 tin tout Mps tps serv  Mps tps serv  Mps tps serv  Mps tps serv   us sy dt id
   0  236   0   0    0    0   0    0    2 148    0    2  42    1    4  8  0 89
   0 1214   0   0    0    0   0    0    7 3583    0    0   0    0    9 14  0 77
   0 2100   0   0    0    0   0    0    7 3531    0    5 157    0    7 17  0 77
   0  941   0   0    0    0   0    0    7 3640    0    0   0    0    7 14  0 79</code></pre></noscript>.<br />
Aha! Our container burns quite a bit of IO. However, we want to know more. Maybe some kind of tracing. Let&#8217;s dtrace. Yep, there is dtrace in /native. I&#8217;m not a dtrace pro, there is tons of materials online. (<a href="http://dtrace.org/">dtrace.org</a>, <a href="http://dtrace.org/blogs/">guide</a>, <a href="http://www.brendangregg.com/DTrace/dtrace_oneliners.txt">examples</a>). We&#8217;ll use the &#8216;lx-syscall&#8217; probe (<strong>L</strong>inu<strong>X</strong>-syscall).`-ln lx-syscall:::` lists lx-syscall probes. -n `syscall::: { @num[execname,pid,probefunc] = count() }` starts the probe, and groups by program, process-id and probe name. Stop the probe with `Ctrl+C`:<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=dtrace-start.sh"></script><noscript><pre><code class="language-shell shell">#linux-syscalls aka lx-syscalls
root@3bd53e4a7fe4:/# dtrace -ln &#039;lx-syscall:::&#039;
   ID   PROVIDER            MODULE                          FUNCTION NAME
 1549 lx-syscall             sys32                     inotify_init1 return
 1550 lx-syscall             sys32                            preadv entry
 1551 lx-syscall             sys32                            preadv return
 1552 lx-syscall             sys32                           pwritev entry
 
# Start tracing the syscalls. Grouped by execname, pid and syscallname (probefunc)
root@3bd53e4a7fe4:/# dtrace -n &#039;syscall::: { @num[execname,pid,probefunc] = count() }&#039;
dtrace: description &#039;lx-syscall::: &#039; matched 1352 probes
^C

  node                                                  23210  fsync                                                         11368
  node                                                  23210  ioctl                                                         11368
  node                                                  23210  open                                                          11368
  node                                                  23210  pwrite64                                                      11368
  node                                                  23210  close                                                         11370
  node                                                  23210  unlink                                                        11370
  node                                                  23210  epoll_wait                                                    30332
  node                                                  23210  read                                                          30332
  node                                                  23210  write                                                         30332
  node                                                  23210  futex                                                        180019
 
</code></pre></noscript><br />
We see our node process is doing tons of write, read, open unlink and futex system calls, so our node process is the issue. But what is this program doing? What files is it opening? Let&#8217;s do more dtrace probes. `x-syscall::open:entry` only shows the open syscall, `execname==”node”` filters out node only. And we group by file with &#8220;@num[copyinstr(arg0)] = count()`.<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=what-file.sh"></script><noscript><pre><code class="language-shell shell">root@3bd53e4a7fe4:/# dtrace -n &#039;lx-syscall::open:entry/execname==&quot;node&quot;/ {  @num[copyinstr(arg0)] = count() }&#039;
dtrace: description &#039;lx-syscall::open:entry&#039; matched 2 probes
^C

  /tmp/io-file-0.00023033588805110305                               1
  /tmp/io-file-0.00029973264092197915                               1
  /tmp/io-file-0.001082331117725488                                 1
  /tmp/io-file-0.0017028727466004145                                1
  /tmp/io-file-0.00224423432995402                                  1
  /tmp/io-file-0.002446706340221372                                 1
  /tmp/io-file-0.002880551536430742                                 1</code></pre></noscript><br />
Ah, tons of temporary files. Hmm&#8230;well where in the node program do we create these temp files? With Dtrace&#8217;s ustack/jstack we can the the programs stack trace:<br />
<script src="https://gist.github.com/674e33d7e8db51040fc00869de0e272a.js?file=stack-probe.sh"></script><noscript><pre><code class="language-shell shell">root@3bd53e4a7fe4:/# dtrace -n &#039;lx-syscall::open:entry/execname==&quot;node&quot;/ {  @num[jstack()] = count() }&#039;
dtrace: description &#039;lx-syscall::open:entry&#039; matched 2 probes
^C


              libc.so.6`open+0x10
              libc.so.6`sysconf+0x54c
              node`_ZN2v88internal20MarkCompactCollector31NumberOfParallelCompactionTasksEil+0x46
              node`_ZN2v88internal20MarkCompactCollector23EvacuatePagesInParallelEv+0xea
              node`_ZN2v88internal20MarkCompactCollector29EvacuateNewSpaceAndCandidatesEv+0x67
              node`_ZN2v88internal20MarkCompactCollector14CollectGarbageEv+0x29
              node`_ZN2v88internal4Heap11MarkCompactEv+0x6d
              node`_ZN2v88internal4Heap24PerformGarbageCollectionENS0_16GarbageCollectorENS_15GCCallbackFlagsE+0x4b0
              node`_ZN2v88internal4Heap14CollectGarbageENS0_16GarbageCollectorEPKcS4_NS_15GCCallbackFlagsE+0x142
              node`_ZN2v88internal4Heap15HandleGCRequestEv+0x84
              node`_ZN2v88internal10StackGuard16HandleInterruptsEv+0x31c
              node`_ZN2v88internal18Runtime_StackGuardEiPPNS0_6ObjectEPNS0_7IsolateE+0x45
              0x2bd84b30961b
              0x2bd84b44e1f9
              0x2bd84b4490eb
              0x2bd84b44281b
              0x2bd84b30d157
              0x2bd84b442615
              0x2bd84b337f84
              0x2bd84b322922
              node`_ZN2v88internal12_GLOBAL__N_16InvokeEPNS0_7IsolateEbNS0_6HandleINS0_6ObjectEEES6_iPS6_S6_+0xb3
              node`_ZN2v88internal9Execution4CallEPNS0_7IsolateENS0_6HandleINS0_6ObjectEEES6_iPS6_+0x61
              node`_ZN2v88Function4CallENS_5LocalINS_7ContextEEENS1_INS_5ValueEEEiPS5_+0x139
              node`_ZN2v88Function4CallENS_5LocalINS_5ValueEEEiPS3_+0x41
              node`_ZN4node9AsyncWrap12MakeCallbackEN2v85LocalINS1_8FunctionEEEiPNS2_INS1_5ValueEEE+0x149
              node`_ZN4nodeL5AfterEP7uv_fs_s+0x146
              node`uv__work_done+0xa5
              node`uv__async_event+0xab
              node`uv__async_io+0xa3
              node`uv__io_poll+0x3a0
              node`uv_run+0x156
              node`_ZN4node5StartEiPPc+0x468
              libc.so.6`__libc_start_main+0xf5
                2

              libpthread.so.0`open+0x2d
              node`worker+0xa1
              node`uv__thread_start+0x19
              libpthread.so.0`start_thread+0xc4
            62043
</code></pre></noscript><br />
Ah&#8230;no luck. The open syscall is in the event loop (Looking into node via dtrace is another topic). However, we know know that the node program creates tons of tmp/io-file files and with this information we hopefully can fix that bug.<br />
<div id="attachment_3316" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/dtrace.en_.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3316" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/dtrace.en_-1024x526.jpg" alt="Sherlock &#039;dtrace&#039; Holmes" width="700" height="360" class="size-large wp-image-3316" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/dtrace.en_-1024x526.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/dtrace.en_-300x154.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/dtrace.en_-768x394.jpg 768w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3316" class="wp-caption-text">Sherlock &#8216;dtrace&#8217; Holmes</p></div></p>
<h2>You know DTrace well?</h2>
<p>You know dtrace well and cannot find many probes? Because you can only dtrace within the Triton container you have less probes available. And we cannot go into the global zone of Joyent&#8217;s public cloud service. On a private Triton deployment we could. That&#8217;s a topic for another time and another blog post.</p><p>The post <a href="https://www.gamlor.info/wordpress/2016/07/joyents-triton-native-our-friend/">Joyent’s Triton : /native, our friend!</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Hey Mr Postman, be on Every Windows Machine.</title>
		<link>https://www.gamlor.info/wordpress/2016/07/hey-mr-postman-be-on-every-machine/</link>
		
		<dc:creator><![CDATA[gamlerhart]]></dc:creator>
		<pubDate>Sat, 09 Jul 2016 14:04:03 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Technical Wibbly Wobbly]]></category>
		<category><![CDATA[containers]]></category>
		<category><![CDATA[turbo.net]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">http://www.gamlor.info/wordpress/?p=3133</guid>

					<description><![CDATA[<p>Postman is probably my favorite adhoc HTTP tool for exploring API&#8217;s, testing, debugging etc etc. Often I go to some other machine, and want to test something on there. Oups:&#8230;</p>
<p>The post <a href="https://www.gamlor.info/wordpress/2016/07/hey-mr-postman-be-on-every-machine/">Hey Mr Postman, be on Every Windows Machine.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Postman is probably my favorite adhoc HTTP tool for exploring API&#8217;s, testing, debugging etc etc. Often I go to some other machine, and want to test something on there. Oups: Chrome nor Postman is installed =(.<br />
Like <a href="https://www.gamlor.info/wordpress/2016/04/need-sql-server-management-studio-now-turbo-net-tipps/">SSMS</a>, I want Postman at my finger tips, on many machines. Why can&#8217;t I just type <code>turbo run postman</code>? That would be lovely, no?!</p>
<div id="attachment_3202" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3202" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman-1024x672.jpg" alt="With V8 and Chrome to Valhalla!" width="700" height="459" class="size-large wp-image-3202" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman-1024x672.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman-300x197.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman-768x504.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/heymrpostman.jpg 1372w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3202" class="wp-caption-text">With V8 and Chrome to Valhalla!</p></div>
<h2>Create a Postman container</h2>
<p>Well, at the moment there is no packaged Postman on Turbo.net&#8217;s hub. But don&#8217;t worry, you can create your own image. Let&#8217;s start. First, we could start up Chrome, navigate to the store there etc: Oh wait, we can do better. On the command line, give it the URL to open up. That URL can be a Chrome store page. Just Google for &#8220;Postman Chrome Store&#8221;, copy and paste the site&#8217;s URL and there we go:</p>
<p><script src="https://gist.github.com/7e58108a14c66895bc255db598071442.js?file=fire-chrome-postman.bat"></script><noscript><pre><code class="language-batchfile batchfile">turbo run --name=postman-chrome chrome &quot;https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en&quot;</code></pre></noscript><br />
This pops open the extension add dialog. Confirm the installation.</p>
<p><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension.png"><img loading="lazy" decoding="async" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension-300x217.png" alt="add-extension" width="300" height="217" class="aligncenter size-medium wp-image-3229" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension-300x217.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension-768x557.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension-1024x742.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/add-extension.png 1308w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>After that, we have Chrome with Postman installed in this container. When we start this container again, Postman is installed there.</p>
<h2>Build a Postman Image</h2>
<p>Now, we actually want a Postman image, not Chrome with Postman installed. We can commit the container to a image and change its launch parameters to start the Postman.</p>
<p>Let&#8217;s do it via a <a href="https://turbo.net/docs/reference/turboscript">Turbo script</a>. With Turbo scripts you can script building new images. Most images on the turbo hub are actually created this way. You can look at the source for most of the images in Github <a href="https://github.com/turboapps/turbome">https://github.com/turboapps/turbome</a>.</p>
<p>Our Postman creating script will be way simpler. It can be adopted for other Chrome apps without any problems. Here it is:<br />
<script src="https://gist.github.com/7e58108a14c66895bc255db598071442.js?file=postman.turbo.me"></script><noscript><pre><code class="language-roff roff"># First we base our image on Chrome.
layer chrome

# Let&#039;s give the image the name roman.stoffel@gamlor.info/postman by default
# Namespace should be your account name or turbo-org account you own.
meta namespace = &quot;roman.stoffel@gamlor.info&quot;
meta name = &quot;postman&quot;

# Let&#039;s start chrome, with the Store page open. Ready to add the Postman extension
# I didn&#039;t find out how to automattically &#039;Accept &amp; Add&#039; the extension. 
# You&#039;ll have to do it manually for now
cmd (&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;,&quot;https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en&quot;) 

# Ok, let&#039;s start up the Postman Chrome app.
# The app-id is the same ID you see in the URL of the Chrome app you want to add
startup file (&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;, &quot;--profile-directory=Default&quot;, &quot;--app-id=fhbjgbiflinjbdggehcddcbncdddomop&quot;) 
</code></pre></noscript></p>
<p>Now, we can run this script to create our Postman image:<br />
<script src="https://gist.github.com/7e58108a14c66895bc255db598071442.js?file=build-postman.bat"></script><noscript><pre><code class="language-batchfile batchfile">turbo build --no-base --overwrite postman.turbo.me</code></pre></noscript></p>
<p>Unfortunately, I did not find out how to automate Chrome to add an extension automatically. So, you have to click &#8216;Add to Chrome&#8217; and wait until it is added. Then close Chrome to continue the script.</p>
<p>Anyway, now you have a Postman image. Push it to the hub, so you can use it in any computer. Now you can go to any box, type in <code>turbo run [your-account/postman</code> into the command line, and bang, Postman will fire up.</p>
<div id="attachment_3205" style="width: 710px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3205" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers-1024x659.jpg" alt="One Postman? More Postmen!" width="700" height="450" class="size-large wp-image-3205" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers-1024x659.jpg 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers-300x193.jpg 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers-768x495.jpg 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/postman-in-containers.jpg 1590w" sizes="(max-width: 700px) 100vw, 700px" /></a><p id="caption-attachment-3205" class="wp-caption-text">One Postman? More Postmen!</p></div>
<h2>Make It Fancy</h2>
<p>If the image is for personal use, then you are probably already happy with the result. If you want to share this image across an organization, you might want to add some meta data. You can go to the Turbo.net hub, go to the repository of the image you just pushed. There you can add a nice icon, some explanation etc. </p>
<div id="attachment_3221" style="width: 310px" class="wp-caption aligncenter"><a href="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3221" src="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page-300x226.png" alt="Adding meta data" width="300" height="226" class="size-medium wp-image-3221" srcset="https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page-300x226.png 300w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page-768x578.png 768w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page-1024x770.png 1024w, https://www.gamlor.info/wordpress/wp-content/uploads/2016/07/edit-page.png 1232w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-3221" class="wp-caption-text">Adding meta data</p></div>
<p>You then can use the <code>turbo installi/subscribe</code> commands to add the Postman image to the start menu etc. That exercise is left for you, the reader ;). Like in my example, <code>turbo installi roman.stoffel@gamlor.info/postman</code></p><p>The post <a href="https://www.gamlor.info/wordpress/2016/07/hey-mr-postman-be-on-every-machine/">Hey Mr Postman, be on Every Windows Machine.</a> first appeared on <a href="https://www.gamlor.info/wordpress">Gamlor</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
