Friday, October 8, 2021

Raspberry Pi excellent result as mini server

"Independent Alternative Film-makers" website running on a Raspberry Pi.

When I retired from Manukau Institute of Technology in 2020, they gave me a present of a "Raspberry Pi" ultra micro computer. The "Pi" is well known to educators and engineers as a "robot brain" device. This however is the latest version 4 which with 4 cores and 8 Gb of RAM can take on the "mini server" role. I therefore set out to migrate this website on to the Pi. It was on a PC with some green quality because it was recovered from recycled parts - but this PC idled at 40 W power consumption, and Pi idles at 4 W. "Idle" is relevant because websites like this typically have only small bursts at the moment of visitor connection with little or no load while a visitor reads a downloaded web page.

The Pi is small enough to hold within the palm of my hand.

In this photo I have created my own enclosure for it adapting a plastic container and adding a small cooling fan.

This website was a challenging candidate for migration to Pi because the tech was "Microsoft WebForms dotNet Framework" which is very much Windows tech. In programming terms this this about the most distant we can get from Pi and its Linux operating system.

About which Linux. The default Pi Linux is "Raspbian" which is optimised for the "robot brain" role. I use the optional alternative Ubuntu 64 bit which is more suitable for the "mini-server" role.

My old website had a "Microsoft SQL Server" database. Microsoft has recently released a version that can run on Linux including Ubuntu. I could not install it and on much searching discovered that it is incompatible with the "RISC ARM-64" CPU silicon chip at the centre of the Pi. The fix for that was a database migration to "Sqlite".

I went at first with using "mono". "mono" is an system that duplicates most of the functionality of "dotNet Framework" for Linux and some other non-Windows systems. This was off to a good start with minor code changes but to get more advanced details working needed more work. I could not get "Session" to work at all and I ended up needing to code an equivalent from the fundamental base of Session cookies. I also found the configuration and setup on Ubuntu to be hard work. I had fastcgi working for about a month then it stopped and I was unable to recover it. I switched to the simpler xsp4 which comes with warnings about it being a lesser test system although it worked well for me. After about 2 months, fastcgi mysteriously started working again, but by then I had moved to "dotNet Core 5".

My other programming is all on the latest "dotNet Core 5" and most of my programming community has also moved on to that leaving only a small population interested in the framework version of mono. I therefore took on the next level challenge and "got current". Fortunately my website makes only limited use of "WebForms" which are not supported in "dotNet Core 5". I was able to replace WebForms with "Razor Pages" which have a similar arrangement where we build 1 web page as 2 files: a "client side" page based on html, and a "server side code behind" page in the "C#" ( c-sharp) programming language.

I tried a little trick that worked, which was to keep the old aspx extension as part of the new name.
e.g. an old page with files:
 "NoticeEdit.aspx" and "NoticeEdit.aspx.cs" becomes new files:
 "NoticeEdit.aspx.cshtml" and "NoticeEdit.aspx.cshtml.cs".
The extensions "cshtml" and ".cs" get hidden under "dotNet Core 5" so the effective names are the same as before and the old menus and links still work.

From my experience, "dotNet Core 5" is smooth and easy to deploy on Linux. The extra programming work for migration is well rewarded by having a good, reliable deployment and run experience.

"Independent Alternative Film-makers" website running on a Raspberry Pi.

Stress testing the Pi by serving video.

Serving video across the internet is high demand for both a mini-server and its programmer (me). So I had to try it. Most videos on this website are relayed from Youtube or Vimeo. Here are 2 of substantial size, setup to play direct from the Pi.

Amandla! The anti-rugby-tour protests of 1981 (Excerpt) 150 MB

Chase Plaza - ASA School of Art students 1989 120 MB

(1) getting these to play and (2) being able to navigate the timeline to play any part of it, aka "scrubbing", are impressive - if they work - you can test this for yourself.