Ben's Blog

maple syrup, nature encounters, self sustainability ben May 14, 2018

Maple seedling

Something is making this year an excellent one for maples to come out of the ground. Maple seedlings are everywhere.

self sustainability ben May 14, 2018

Marking rocks to save mower blades

I’ll pop them out when the backhoe is attached. I took a lots of rocks out and these are the last ones :).

agriculture, self sustainability ben May 11, 2018

18 more blueberries in the ground

all out geekery, I.T. ben May 05, 2018

Nosy Monster alive and well

The Nosy Monster has been sitting on my desk idle for a while now, I’ve always wanted to work on it a bit and make it more reactive to web input. Finally, I bit the bullet and it’s now a lot smoother to operate. Instead of clicking for pre-timed commands, the start of a key press actuates and the end stops. With a websocket communication layer and a socket python command server, the commands find their way from keyboard to motors super fast.

To account for wireless imperfections and AP hopping, I also wrote the logic such that there isn’t a “start” and a “stop” command. Instead there is only a “start” command which gets sent every 200ms and if it isn’t heard every 300ms, Nosy Monster stops. This ensures it won’t be locked in a state of actuation which could lead to perilous situations.

I intend on polishing the code & publish a tutorial that hopefully a 7 year old could handle.

The Nosy Monster was deployed at the Dartmouth Thayer School of Engineering’s open house. I didn’t know how robust it was going to be under sustained kid use.

It turned out to be a huge hit, I let the kids drive it around a bit and then I’d throw the Nosy Monster in another room where they would have to find their way around with no visibility other than the camera. It performed flawlessly through the evening.

It’s always an enormous point of satisfaction to see kids get into something you made. Once I sent the RC car “to Mars” (the other room), the kids were really focused.  All but one got stuck and never came home. I should have had a prize for the one, but what’s next, participation trophies?

With a much more usable and reliable toy, I decided to setup the same kind of maze in a house room under construction.

I moved the camera up on a stick for a better angle of vision, the next model will have a fisheye camera.

Without a reverse, it takes a few tries to get through the maze without getting stuck. He had to learn to be careful.

I’m bubbling up with ideas  of cool things to do with the concept and acquired techniques. From a solar powered exterior land rover, to battle bots.

agriculture, self sustainability ben April 28, 2018

Oddly fascinated by the leaves

We’ve been watching an excellent crowdfunded documentary series called Woodlanders. It brought to our attention a guy working to reintroduce the chestnut tree to American forests. We couldn’t believe it was even possible to acquire young chestnuts so we pretty much had to place an order. It arrived this week and to our surprise it still had leaves from the season previous. This is when it hit us what it meant to be planting this.

aesthetics ben April 24, 2018

Mandala session on a huge touch screen

agriculture, self sustainability ben April 24, 2018

Spring finally showed up

We’re moving the garden to an area closer to the house and with much better soil

Found a few carrots from last season 🙂

Added 18 blueberry plants to the ~40 we have now; 18 more to come in 2 weeks.

self sustainability, wood ben April 17, 2018

As green as it gets

I threw the last logs in the stove and promptly went after a couple more small ash trees. For a brief moment, we were all out of firewood.

We’ll take all the drying we can get

This is the greenest we’ve burnt, literally minutes between tree to firewood. Ash is seriously impressive.

self sustainability, solar power ben April 11, 2018

Solar monitoring back online

The solar instrumentation has been lacking for a couple of months since the solar panels’ current sensor blew up. It took 2 months because there has been a lot mistakes and learning along the way. It should have been simple, replace the 30A sensor by a 100A one right?

Well it wasn’t. First I ordered the wrong 100A sensor, meant for AC use. Then I had a myriad of issues around calibration.

  • at the 5V input port, a 0V reading didn’t translate to 0A, this sensor goes from -100A to 100A so it is 2.5V which translate to 0A.
  • with the skew from miscalibration, the value I was getting made no sense for what I know the panels can make
  • orientation matters as again, this sensor can read negative values
  • a cloudy day makes fluctuations hard to detect
  • moving the sensor from one interface kit to another after calibration resulted in another skew.

All these little things I could have picked on their own, but together they conspired to make me thoroughly confused and left me seeking support from the Phidgets forums. I was once more impressed by Phidgets, the help I got was fast and efficient. Phidgets are more expensive but I was proven once more that they are worth every penny. They have many other advantages, I have nothing but good things to say about them.

Calibration, I really need to tidy things up in there

I’ve learned a LOT of lessons with this one. Not the least of which is to be ok with the imperfections of analog data. I’m a discrete data type of guy, it doesn’t come naturally to accept skews & variations.

agriculture, self sustainability ben April 11, 2018

Too early for berry

Winter is clinging on this year

 

The blueberries which showed up in the mail will have to wait a few days in the greenhouse.

maple syrup, self sustainability ben April 09, 2018

Sugaring over

This has been an amazing year for sap flow but we did not make the most of it. I was doing the heavy labor by myself, wood was running out, Winter had been long, boiling days unpleasant. So we pulled the plug being satisfied with 6 gallons which will suffice for our yearly consumption.

building, self sustainability ben April 09, 2018

Shiplap all over

Shiplap shipment

This little guy is about to get a very nice bedroom

aesthetics ben April 05, 2018

Rorschach Stream

[mejsvideo mp4=”http://ben.akrin.com/videos/rorschach_stream.mov.mp4″ ogg=”http://ben.akrin.com/videos/rorschach_stream.mov.ogv” webm=”http://ben.akrin.com/videos/rorschach_stream.mov.webm” poster=”http://ben.akrin.com/videos/rorschach_stream.mov.jpg” width=”640″ height=”360″]

aesthetics ben March 28, 2018

The Power of One pen stroke

[mejsvideo mp4=”http://ben.akrin.com/videos/the_power_of_one_pen_stroke_03.mov.mp4″ ogg=”http://ben.akrin.com/videos/the_power_of_one_pen_stroke_03.mov.ogv” webm=”http://ben.akrin.com/videos/the_power_of_one_pen_stroke_03.mov.webm” poster=”http://ben.akrin.com/videos/the_power_of_one_pen_stroke_03.mov.jpg” width=”640″ height=”360″]

self sustainability, wood ben March 19, 2018

Just in time fire

We’ve had no wood reserves for 2½ months, what little left we had was consumed by the unexpected or trying to make starting fires quicker. It’s ok though we’ll be warm, fuel literally grows on trees. All it takes to harvest is a bit of exercise, a beautiful day doesn’t hurt.

Ash trees have a special place in our hearts given how many times they saved our bacon. It’s a shame they are getting ravaged by the emerald ash bore, what will the future ill-prepared homesteader do when their wood reserves don’t meet the tribute demanded by Winter?

Working my way up to the canopy

I was taught to not waste a branch, I moved the canopy elsewhere for later processing, for now I need the quick yield of the trunk

Big logs going for a hike

A fair amount for the time spent.

 

The tire technique

A few swings later, splitting small to help the burn

Straight into the firebox it goes

miscellaneous ben March 19, 2018

Protected: Late Snow is Plentiful Snow

This content is password-protected. To view it, please enter the password below.

maple syrup, self sustainability ben March 18, 2018

If yum was a color

The syrup gets darker as the season progresses

The operation is still on hold pending more clement weather.

miscellaneous ben March 18, 2018

Protected: ATV Ski

This content is password-protected. To view it, please enter the password below.

maple syrup, self sustainability ben March 11, 2018

Sugaring paused

We’re at 3 gallons of syrup so far.

The usual dusk collection

3 days boiling outside into the night, I just want to go home.

 

Pulling the plug

 

Snow storm forced a break, good 🙂

I.T., maniacal paranoia, web development ben March 03, 2018

Turning your web traffic into a Super Computer

Full disclaimer:

The subject matter of this post is controversial as it discusses extracting computing resources from the visitors of a website. There are a lot of discussions at the moment centered around web-browser based crypto currency mining. Most paint a deplorable picture of the practice; please keep in mind that there are very desirable paths alongside which these practices can develop. I am not elaborating on these arguments here, I am only describing a method to harness the resources.

Premise

Web browsers are becoming quite powerful for code execution. Between Javascript’s increase in capability, WebAssembly, access to GPU & threading, a web browser today is almost as desirable for computing as the machine it’s running on. Ever since the rise of web-based crypto currency miners, I’ve been thinking of harnessing all that computing power as a single entity: a super computer made of your visitor’s web browsers.

Just like a regular computer cluster, the nodes all participate in a coordinated fashion to solving a single problem. Unlike a regular computer cluster, the nodes are very ephemeral (as website visitors come and go) and can’t talk to each other (no cross site requests).

Here’s a demo of what I came up with:

Right: the super computer control server
Left: one of the web clients contributing to the super computer simply by being connected to a website (& CPU metrics)

[mejsvideo mp4=”http://ben.akrin.com/videos/transient_node_javascript_supercomputer.mov.mp4″ ogg=”http://ben.akrin.com/videos/transient_node_javascript_supercomputer.mov.ogv” webm=”http://ben.akrin.com/videos/transient_node_javascript_supercomputer.mov.webm” poster=”http://ben.akrin.com/videos/transient_node_javascript_supercomputer.mov.jpg” width=”640″ height=”360″]

The problem being solved here is the hashing of 380,204,032 string permutations to find the reverse of a given hash. Problem parameters were chosen to make heavy processing quick for the clients.

Implementation & code samples

At the core of the idea is the websocket technology. It creates a persistent connection between a server and all of the nodes (the visitors of your website). This connection can be used to orchestrate actions between the nodes so that they can act as a concerted entity. From delivering the code to passing messages for coordination, websockets are what make everything possible.

Having a websocket connection to clients dramatically changes what you can do with web clients. They are fully addressable for the duration of their visit. They may show up on a website and be served some pre-established javascript; but with websockets, any javascript can materialize at any time.

Right: the super computer control server
Left: a web client being given an instruction on the fly

 

Slightly tangential but still worth considering, using a web view app, Javascript can pass execution to the app itself. This means code showing up on the websocket can escape the webview bubble and go into app land.

Right: the super computer control server
Left: a web app being given an instruction which percolates to the app layer

 

Now this is nothing new in a lot of ways; apps can be made to get instructions from C&Cs, and websites can get Javascript after the initial page load from dynamic sources. The websocket technique though is as dynamic as it gets (no Ajax pull), it is portable to many browsers and many devices, it is hard to catch looking at a web inspector; lastly, it executes with full access to the context it materialized in.

So we’ve established that websockets can be used to dynamically deliver code to be ran by the nodes. It can also be used for message passing and the overall orchestration of distributing the problem to be solved.

Crackzor.js

6 years ago I wrote a ditributed OpenMPI based password cracker: crackzor. Password cracking is a good distributed problem to solve because it’s a fairly simple problem: run through all the character permutations. The fact that it exhausts a known space also means benchmarking is easy. So to put the idea of a transient node javascript super computer in practice, I rewrote crackzor in JS instead of C, and for websockets instead of OpenMPI.

Every distributed problem is different and crackzor itself isn’t a magic way to distribute any problem to be solved. The magic of crackzor is its ability, given a space of character permutations, to divide it up in chunks which can be processed by the nodes. Given the problem, a start iteration and end iteration, a node can get to work without having to be provided the permutations themselves, thus removing the bandwidth bottleneck.

The first challenge: maximizing usage of the node’s CPU.

Javascript runs single threaded by default, so when the websocket sends code to be ran by a client, by default, the code running as fast as it can will only be able to fill one core of the CPU. A large majority of machines today have many more cores available. So we have to figure out how to use them or our super computer is going to loose a large portion of its processing power right off the bat.

Web workers to the rescue. With HTML5, it’s easy as pie to thread code. The one trick with the code we want to thread is that it can’t be gotten from a file as the web worker documentation suggests. That’s because our code doesn’t come from a static javascript file remember? It shows up out the the blue on the websocket, so it came from the network and is now in memory somewhere => not a file we can refer to.

The solution is to wrap it in a blob as such

[code language=”js”]var worker_code = ‘alert( "this code is threaded on the nodes" );’

window.URL = window.URL || window.webkitURL;

var blob;
try {
blob = new Blob([worker_code], {type: ‘application/javascript’});
} catch (e) {
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
blob = new BlobBuilder();
blob.append(worker_code);
blob = blob.getBlob();
}
workers.push( new Worker(URL.createObjectURL(blob)) ) ;[/code]

Here you’ll notice we have our first layer of encapsulation. The code relevant to the problem we are solving is in the variable worker_code, the rest of the javascript only threads it.

Having distributed amongst a node’s cores, we now look at

the second challenge: distributing between the nodes

This work is obviously up to the websocket server along with subsequent coordination. Without going into too much details, the websocket server keeps track of all the nodes as they come and go, it also keeps track of which ones are working or not, allocates new chunks of the problem to nodes as they become available.

A trick of the websocket server is that it is running at all times to handle node connections. Super computer problems however may change from one day to the next. To address that, I give it a function which reads a file and evals its code; the function is summoned by a process signal. As such:

[code lang=”js”]function eval_code_from_file() {
if( !file_exists("/tmp/code") ) {
console.log( "error: file /tmp/code does not exist" ) ;
} else {
var code = read_file( "/tmp/code" ) ;
code = code.toString() ;
eval( code ) ;
}
}

process.on(‘SIGUSR1’, eval_code_from_file.bind() );[/code]

With this puppy in place, the next time I “kill -USR1 websocket_server_PID”, it will be imbued with new code that did not exist when it started. Does this sound familiar? Yup, javascript is super interesting in the ability it gives you to run arbitrary code at any time with full access to the established context.

Thus arrive the 2nd and 3rd layers of encapsulation, the code which will be distributed to the nodes is in a file which is to be evaled on the websocket server side and sent over the websocket to the clients.

The actual distribution to the nodes is simple, have them connect with a callback to eval code. Something like that:

Client:

[code lang=”js”]var websocket_client=io.connect("http://websocket_server.domain.com") ;
websocket_client.on( "eval_callback",function(data){data=atob(data),eval(data)}.bind() ) ;[/code]

Server:

[code land=”js”]client_socket.emit( "eval_callback", new Buffer("alert(‘this code will run on the client’);").toString("base64") ) ;[/code]

Recapping where we are

So…

  1. all the transient nodes (web browser of website visitors) attach to a websocket server
  2. the websocket server receives SIGUSR1 which signals it to execute new code it gets from a file
  3. this new code gives the websocket server a packaged problem to be solved by the nodes
  4. this new code also instructs how the websocket server will distribute and coordinate the nodes
  5. once the packaged problem to be solved shows up on a node, it is evaled and it contains threading to maximize CPU usage.

And there you have it,

all the pieces you need to make a super computer from your web traffic. I’m choosing not to publish the full code of my implementation for reasons of readability, security and complexity but I can go into more details if asked.

The same way that peer-to-peer protocols made any data available anywhere any time, could this do the same for computing power? Mind=blown, and your CPU along with it.

More tips

  • When choosing a chunk size for clients to work on, it’s important to not pick too big a size. The nodes are very transient and a big chunk size means the chunk’s processing is more likely to be interrupted. Most web browsers also offer to kill poorly coded javascript running berserk and so a small chunk size taking a few seconds and letting the machine catch it’s breath briefly will make it less likely that a browser will notify a user that a script needs to be killed.
  • When encapsulating out the wazoo, keep in mind that Internet Explorer (Edge or whatever it’s called today) doesn’t support backticks.
  • Syntax highlighting will be confused by the strings in strings in strings of encapsulation, it helps to just turn it off.
  • Javascript md5 implementation here: https://gist.github.com/josedaniel/951664
  • I found it necessary to keep track of an average time to solving a chunk so that I may exclude the nodes which are taking too long and polluting the good performance of the supercomputer.
building, self sustainability ben February 27, 2018

Light construction week end

Finally finished the insulation & vapor barrier upstairs, got started on the staircase.

Mud season has officially started and this little path will make trips to the well a lot easier.

maple syrup, self sustainability ben February 22, 2018

Protected: Let the sap flow

This content is password-protected. To view it, please enter the password below.

nature encounters ben February 21, 2018

Maple Camouflage

 

not the best choice during Sugaring season

Posts pagination

← Previous 1 … 26 27 28 … 52 Next →

This blog is solar powered

Interactive

Handwriting Capture
Mandalagaba
IPv6 link-local to MAC converter
IPv6 MAC to link-local converter
Markov Text Generation
Markov Word Generation
Markov Music Generation
Duplogrifier
Flood Fill Algorithms
Homestead Metrics
RGB Playground
Web Games

Categories

  • aesthetics111
    • plots54
    • specular holography6
  • Books4
  • I.T.204
    • 3D modeling / printing21
    • AI7
    • all out geekery37
    • electronics28
    • homestead automation7
    • maniacal paranoia27
    • plotters49
    • unix / linux29
    • video games4
    • web development30
    • web games3
  • Lego / Duplo67
  • life in the U.S.42
  • miscellaneous204
  • nature encounters115
  • old vinyls3
  • organs2
  • self sustainability563
    • agriculture107
    • apiculture38
    • apple20
    • building132
    • canning3
    • crochet6
    • foraging6
    • hunting10
    • maple syrup47
    • poultry39
    • preserving2
    • solar power28
    • water23
    • wood84
  • trip to a new life6
Theme by Bloompixel. Proudly Powered by WordPress