<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Debugging on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/debugging/</link><description>
Recent content about Debugging from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/tags/debugging/feed.xml" rel="self" type="application/rss+xml"/><item><title>Rules for working with dates and times</title><link>https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</link><guid isPermaLink="true">https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</guid><pubDate>Sat, 07 Mar 2020 15:35:49 +0000</pubDate><guid>https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</guid><description><div>Dates and times are incredibly complex. They can be different in different countries, languages. They are often inconsistent and have weird edge-cases. These are some basic rules I apply when working with dates and times.</div><div>&lt;p>when handling dates and timestamps, here are the foundation rules that I work to:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Always use ISO date format where possible&lt;/strong> (YYYY-MM-DD)&lt;/p>
&lt;p>So that there can be no ambiguity and so that date strings will naturally sort&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Always work in UTC&lt;/strong> (Aka Zulu time or GMT) except when displaying to the user&lt;/p>
&lt;p>To avoid weird errors, especially with timezone and daylight savings transitions. It also makes date/time calculations a LOT easier.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>When needing a string format for timestamps, always use ISO format&lt;/strong>&lt;/p>
&lt;p>e.g. &lt;code>2020-03-07T15:27:46.123Z&lt;/code>&lt;/p>
&lt;p>These are always unambiguous and easily machine parsed.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>When specifying decimal seconds in a timestamp, avoid more than 3 decimal places&lt;/strong>&lt;/p>
&lt;p>The &lt;a href="https://github.com/gr2m/moment-parseformat">parsing tool&lt;/a> used in &lt;a href="">node-red-contrib-moment&lt;/a> to parse input dates in different formats cannot cope with more than 3dp and may return strange dates, a problem that I reported in May 2019 but hasn&amp;rsquo;t been resolved.&lt;/p>
&lt;p>It should also be noted that I&amp;rsquo;m not sure that MomentJS can cope with more than 9dp.&lt;/p>
&lt;p>Also worth noting that JavaScript&amp;rsquo;s &lt;code>Date&lt;/code> native object only supports up to 3dp anyway and will turn anything beyond that into zero&amp;rsquo;s.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://github.com/gr2m/moment-parseformat/issues/96">parseFormat function issue for &amp;gt;3dp seconds resolution&lt;/a>&lt;/p>
&lt;p>The worst thing about this issue is that it can result in an incorrect date being returned but does not give a warning.&lt;/p>
&lt;/li>
&lt;/ul></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/information-management">Information Management</category><category domain="https://it.knightnet.org.uk/categories/data">Data</category><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/software">Software</category><category domain="https://it.knightnet.org.uk/tags/databases">Databases</category><category domain="https://it.knightnet.org.uk/tags/dates">Dates</category><category domain="https://it.knightnet.org.uk/tags/dba">DBA</category><category domain="https://it.knightnet.org.uk/tags/debugging">Debugging</category><category domain="https://it.knightnet.org.uk/tags/development">Development</category><category domain="https://it.knightnet.org.uk/tags/software">Software</category><category domain="https://it.knightnet.org.uk/tags/solutions-architecture">Solutions Architecture</category><category domain="https://it.knightnet.org.uk/tags/standards">Standards</category><category domain="https://it.knightnet.org.uk/tags/timestamps">Timestamps</category></item><item><title>Cleaning up npm package install problems</title><link>https://it.knightnet.org.uk/kb/nr-qa/clean-up-npm/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/clean-up-npm/</guid><pubDate>Wed, 05 Jun 2019 07:05:39 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/clean-up-npm/</guid><description><div>Node-RED uses npm to manage package installations such as its nodes.
Sometimes, you can get into a situation where you start getting lots of npm installation or removal issues and it feels like you are going round in circles trying to fix things. If so, time to call it a day and to get drastic! Here, I try to explain an easy way to fix things quickly and completely without side effects.</div><div>&lt;p>Node-RED is built over Node.js which uses &lt;code>npm&lt;/code> as its library (AKA package) manager. It is great to have a standard mechanism to manage libraries but the complexities of managing JavaScript based packages sometimes trips things up.&lt;/p>
&lt;p>Once you&amp;rsquo;ve tried for a bit to understand what the issues are, it may be time to call time and get drastic.&lt;/p>
&lt;p>The following commmands will clean out the packages installed for your live instance of Node-RED - assuming you have it installed via the &amp;ldquo;standard&amp;rdquo; default method. If not, you will need to adjust the folder you operate in.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">cd&lt;/span> ~/.node-red
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rm package-lock.json
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rm -R node_modules
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">npm install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>That will cleanly reinstall all of the packages marked in your &lt;code>package.json&lt;/code> file. So make sure that is correct first. Every time you install a package (as long as you have reasonably up-to-date versions of Node.js and npm) whether from the NR admin ui or command line, it gets added to package.json.&lt;/p>
&lt;p>I now always remove the lock file as well if I&amp;rsquo;m having issues as that can be the cause of some issues. The lock file isn&amp;rsquo;t generally needed in NR installations.&lt;/p>
&lt;p>Note, as always, I&amp;rsquo;ve assumed you have a &amp;ldquo;standard&amp;rdquo; install of Node-RED which puts your userDir as &lt;code>~/.node-red&lt;/code> (and the equivalent on Windows). If you use an installation scheme like mine, it will be in a different place as noted by the command used to start NR.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/npm">npm</category><category domain="https://it.knightnet.org.uk/tags/node.js">Node.JS</category><category domain="https://it.knightnet.org.uk/tags/javascript">JavaScript</category><category domain="https://it.knightnet.org.uk/tags/debugging">Debugging</category></item><item><title>Analysing the Performance of Node-RED</title><link>https://it.knightnet.org.uk/kb/nr-qa/analysing-performance/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/analysing-performance/</guid><pubDate>Fri, 19 Apr 2019 13:23:06 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/analysing-performance/</guid><description><div>Node-RED is a powerful platform for prototyping and rapid development but it is complex. It has a lot of moving parts and it can be hard to know what might be causing performance bottlenecks.
This article tries to give some hints and tips about analysing those bottlenecks and how to resolve them.</div><div>&lt;p>Sorry, this is draft and far from complete. Please leave comments if you have something useful to add. Thought I would publish anyway in case anyone finds it useful. I will try to come back to it in the future. If you leave a comment, it will remind me. :-)&lt;/p>
&lt;h1 id="platform">Platform&lt;/h1>
&lt;p>Before starting more detailed analysis, the first thing to do is to look at the platform being used to run Node-RED.&lt;/p>
&lt;p>Often, something like a Raspberry Pi or other single-board computer (SBC) is being used. They have very limited resources and often slow storage (e.g. SD-Cards). So it is very easy to overload them and kill performance.&lt;/p>
&lt;p>To analyse this, you need to use a tool such as &lt;code>top&lt;/code>. Better still, get something a bit more comprehensive such as &lt;code>glances&lt;/code>. Either way, these will tell you how much CPU and memory (RAM) is being used and by what. Start by looking at the three &amp;rsquo;load&amp;rsquo; values, these should all be fairly low, if they are going over about 2-3 regularly then you have an issue.&lt;/p>
&lt;p>Next look at the &amp;lsquo;swap&amp;rsquo;. If this is being used regularly, you will have a performance bottleneck because memory (RAM) is being overused. To fix this, you have to unload some services. If using the &lt;code>glances&lt;/code> tool, it will show a warning if the memory is swapping.&lt;/p>
&lt;p>The easiest way to remove load is likely to be turning off the &amp;lsquo;desktop&amp;rsquo;. This gives you a GUI that you directly interact with via keyboard and monitor. Removing this will remove lots of load on memory and CPU. Have a look at articles that explain how to run your device &amp;lsquo;headless&amp;rsquo;. You will need to be able to connect to your device over the network from another device.&lt;/p>
&lt;p>After that, if there are still issues, you need to look at taking off services that you don&amp;rsquo;t actually need running.&lt;/p>
&lt;p>Finally, if you still have issues, you will need to think about splitting services between multiple devices or using a more powerful device.&lt;/p>
&lt;h1 id="back-end-server">Back End (server)&lt;/h1>
&lt;h2 id="using-nodejs---inspect-option">Using Node.JS &lt;code>--inspect&lt;/code> option&lt;/h2>
&lt;h1 id="front-end-browser-node-red-admin-ui">Front End Browser (Node-RED Admin UI)&lt;/h1>
&lt;p>For any browser performance issues, you firstly need to ensure that the problem is actually coming from something related to Node-RED. So you should turn off any browser extensions before continuing. An extension such as SimpleExtManager for Chromium browsers will assist with easily turning on/off extensions.&lt;/p>
&lt;h2 id="browser-performance-profiling">Browser Performance Profiling&lt;/h2>
&lt;p>Using your browser&amp;rsquo;s developer tools, you are able to record and analyse a performance analysis. The Chromium developer tools have three tabs to help with this. Performance, Memory and Application.&lt;/p>
&lt;p>The Performance tab is perhaps the easiest to get going with. Click on that tab and then start profiling. Leave that for an amount of time that you estimate will let you see any ongoing performance issues. That might be just a few seconds or a few minutes. You will want to tick the &amp;ldquo;memory&amp;rdquo; option and probably don&amp;rsquo;t need the &amp;ldquo;Screenshots&amp;rdquo; option.&lt;/p>
&lt;p>The thing to look at first is likely to be the memory utilisation. There is a graph 1/2 way down the display that shows you some important metrics including the &amp;ldquo;JS Heap&amp;rdquo;. See how big that is getting by hovering over the line. Also look at how fast it is growing. You should see that the heap reduces periodically as the JavaScript engine does a &amp;lsquo;garbage collection&amp;rsquo;.&lt;/p>
&lt;p>You can also do multiple recordings and compare the heap over a longer period.&lt;/p>
&lt;h1 id="front-end-dashboard-uibuilder-http-in-out-nodes-etc">Front End (Dashboard, uibuilder, http-in/-out nodes, etc.)&lt;/h1></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/node.js">Node.JS</category><category domain="https://it.knightnet.org.uk/tags/javascript">JavaScript</category><category domain="https://it.knightnet.org.uk/tags/debugging">Debugging</category><category domain="https://it.knightnet.org.uk/tags/performance">Performance</category></item></channel></rss>