A Rusty Conundrum and Rustic Thoughts about Web Servers

avatar

This post examines a rusty pipe and contemplates building a web site from Rust.

Pipe Dreams

The picture above shows a conumdrum. The pipe coming from the garbage disposal rusted and is leaking. My family has a service contract with a local plumbing firm. When the plumber looked at the problem he broke the screw that holds the garbage disposal to the pipes; so to repair the pipe he has to replace the garbage disposal. His quote for the repair was about $780.

I bought a $6 pipe to replace the broken pipe and used epoxy to fix the screw. I have to decide: should I pay $750 to fix the problem or live with my quick fix? This is a picture of the rusted pipe.

Building on Rust

I really enjoy web programming.

Come to think of it. There was a time when I enjoyed participating in online forums about programming.

The technorati became so petty and vicious that my love for programming vanished.

I've used a variety of platforms for the web including Domino by Lotus, Oracle HTTP Server, Tomcat and the venerable LAMP Stack.

I ended up disliking each of the servers because they were far too complex. These large platforms have a history of injecting expensive dependencies into my projects. The dependencies have systemically destroyed each of my web projects.

I actually thought that the Oracle HTTP server was the most elegant of the servers I used as it was optimized for data driven programming.

Unfortunately, Oracle has outrageous licensing fees and Oracle itself has a footprint which is far too heavy for smaller web sites.

I took a fancy to the LAMP stack because PHP was a sufficient for the job of moving data from a database to a web page and it was available for free on discount web hosts.

In my opinion, PHP has one primary job. It needs to move data from a database into a web page. Its first database connection programs had a few security holes.

PHP fell for the idea that all code must be written using the class-structure popularized by C++. PHP deprecated its database functions with a structured called PDO based on Microsoft's ODBC. There are some bugs in PDO that causes it to return the wrong data in some circumstances and it is just too awkward for serving simple web pages.

I've been at a loss for over a decade. I want to help small businesses get online, but I no longer recommend PHP. As far as I am concerned PHP destroyed its core project.

The Whole Software World is Suffering from Bloat

Web Servers are not the only programs that suffer from bloat.

Computer programs tend to follow a similar pattern: The first generation of a program is lightweight and extremely nimble. The keepers of the stack have a habit of adding bells and whistles to their programs to attrack customers. The new features tend to have new security holes. As the program ages, the once nimble program turns into an unweildy monster.

This problem happens to all sorts of programs

The programming group called Mozilla produces a web browser called Firefox. As Firefox struggled through the browser wars, it became exceedingly bloated. Firefox had numerous memory holes and other problems that would cause the program to slow down.

Many of the problems seem to stem from the class-structure used by C++. C++ uses a complex "garbage collector" to free memory. The picture of a broken garbage disposer is relevant to the post.

Some marketers call the class-structure used in C++ and Java an "object." The markets then call C++ and Java "Object Oriented Programming Languages." The class structure used in C++ and Java is not a good implementation of the ideas behind object design.

In 2010, Graydon Hoare suggested that Mozilla could reduce the bloat and bugs in their program by adopting a functional approach to design. The functional approach eliminates the need for garbage collection and onerous code needed to track the "objects" created by the C++ class-structure.

Hoare and cohorts created a new programming language and compiler called Rust. Mozilla began rewriting parts of Firefox and released a streamlined browser to the public in 2015.

Intrigued by Rust, I decided to read the Rust Book. This book ends with the creation of a multithreaded website that uses a simple HTTP listener.

The following code, copied from the document, is a simple web listener (aka a web server) that returns the file "hello.html" on port 7878.

use std::fs;
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;

fn main() {
    let listener = TcpListener::bind("127.0.0.1:7878").unwrap();

    for stream in listener.incoming() {
        let stream = stream.unwrap();

        handle_connection(stream);
    }
}

fn handle_connection(mut stream: TcpStream) {
    let mut buffer = [0; 1024];
    stream.read(&mut buffer).unwrap();

    let contents = fs::read_to_string("hello.html").unwrap();

    let response = format!(
        "HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
        contents.len(),
        contents
    );

    stream.write(response.as_bytes()).unwrap();
    stream.flush().unwrap();
}

I've been staring at this code thinking that it might be possible to build a robust web server from scratch in Rust.

I could make some money by documenting the fiasco, errr ... I mean my experiment, using HIVE.

I had tried doing this a long time ago using C++ and sockets. But, since I couldn't afford to rent a dedicated server at the time, I gave up on the experiment.

There are a couple of companies that offer virtual private servers including Digital Ocean and VPS.net for $5 a month.

If you looked in my wallet; you will see that I have $5 worth of HBD. I am thinking of taking that $5 HBD and renting me a Virtual Private Server at VPS. If it works, I might replace all of my web sites with Rust sites.

I will create a programming diary with code on my homepage. Since my account name is @yintercept I think I will call the web program ysrv . My posts will use the #ysrv tag.

Interfacing with HIVE

I hope to fund this site with the money I receive from my HIVE posts. This brings up the question of which front end to use. Since I am writing about programming, my first instinct is to use StemGeeks #STEM .

In this project, I want to talk about the philosophy behind coding. My second impulse was to use Proof Of Brain #POB. I finally decided to start the project on Verify Your Brain simply because #VYB is one of the newest interfaces to HIVE.

After the server is running, I would like to find ways to intergrate it with #hive-engine . So, I thought about using TribalDex Blog #hive-engine .

The developers of the HIVE blockchain are only interested in code written in Python or Node.js. While it is possible to create web sites with python and node.js. I want to code with a lower level language such as Rust or C.

Please let me know your thoughts on the interface I should use for the project? Should I engage in tag spam and do the project on multiple tribes . This is what most HIVEans seem to do.

PS: while I am starting the project in Rust, I might switch to C midstream.

Anyway, I think I will take a walk. When I come back I will order my VPS server. I think I will use Debian as the OS. The goal of this project is to create a web server with a minimal number of dependencies. My next post will be about setting up the server.



0
0
0.000
6 comments
avatar

I want to learn more about the core concepts of coding, so I would certainly be interested in following such a journey and adding my dollar-ish of upvote power.

0
0
0.000
avatar

Plumbing is not rocket science, nor even stagecraft, if it doesn't leak, I'd leave it.
If it does leak, I'd look at the nearest hardware store for a garbage disposal and do the job myself.
It is a pretty straight forward thing to do.

0
0
0.000
avatar

If you look at the picture; you will see that I fixed the last leak with silicone tape.

Silicone tape did a fantastic job. I thought about wrapping the broken pipe with silicone tape. That probably would have done the job.

I am not the one who makes the decision about the repair; however, I patched the leak with a pipe section I got from ACE, some plumbers putty and epoxy glue.

The house was built in the 1950s. The plumber gave a price on all of the plumbing work that needs to be done on the house. The total quote was over $20,000. The electrician gave us a similar bleak quote about electric repairs.

Personally, I suspect the house will be ripped to its foundations and rebuilt when my parents move out in a decade or so.

0
0
0.000
avatar

The idea behind object oriented programming is really reuse, not necessarily because it makes for more efficient code. This is good perhaps if you are developing large software projects or libraries but for smaller projects, good object oriented programming is more trouble than it is worth.

I prefer simplicity and still love the "old-fashioned" CGI scripting approach. It isn't the most scalable of course but I love how straightforward the concept is.

0
0
0.000
avatar

I think that OOP became a confused paradigm. Every company wanted to use the term "object" in their marketing literature, but they all used the term in different ways.

A notable example is that people started calling the "class structure" in C with Classes an "object."

From a design perspective, I simply saw object-oriented as a way of grouping programs and associated data.

I didn't write many C programs that interfaced with CGI. PHP, of course, was a scripting language that streamlined the interface with CGI and was sufficient for most tasks. CGI is quite close to what needs to be done.

0
0
0.000
avatar

Well, a class is what you use to instantiate an object so if you are writing code with classes then you must at least be creating objects. Whether or not it's good object oriented design or not is another matter entirely.

The great thing about CGI is that you can really use any language at all. C was common and so were shell scripts. I even used Java once for fun. PHP and sevlets and virtually everything since containerized things so that you didn't have to instantiate a new process each time a call was made which definitely makes things more efficient and scalable from an executable standpoint but a lot of programming complexity was added along the way as well. Or at least I thought things became less intuitive.

0
0
0.000