Posts

How long NodeJS setTimeout takes on various environments?

Image
A while ago, I posted about latency spikes while sending messages through RabbitMQ. I'm back to the latency topic with a bit more measurements. The results back then turned out to be a bit of mystery and surprise to me, and latency is not something that can be easily debugged. It took many small steps to better understand what's happening. First of them, was closer look at what impact does the environment have on the test. One of the things that I tried back then was running benchmarks in VirtualBox on idle MacBook Pro - my primary home machine. I was also using an ageing ThinkPad laptop with 32bit CPU, but it's results were hardly comparable to 64bit architectures so I left it. Anyway, VBox+MacBookPro turned out to be fairly bad idea, because those extra layers add a lot of noise, whereas latency test is exactly that moment in time when you don't want any noise. Running the tests in the cloud (i.e. DigitalOcean) appeared to be much better because that way, each

Talking with DigitalOcean from shell or JSON + bash = rcli

RESTful APIs with JSON are all over the software world.  SaaS, PaaS and other aS'es frequently expose HTTP endpoints that eat and breed JSON. They're fairly easy to work with by using almost any language, except when it comes to do something really simple from a shell script. Having extremely positive experience with JavaScript library Ramda that makes JSON processing very verbose, I'm now discovering new uses of it's command-line sister - Rcli: Ramda for Command line . DigitalOcean example Let's pretend we have a droplet in DigitalOcean and want to run a script on it. We're going to figure out droplet IP using API and run some script there via ssh. Sounds ideal for bash script. IP=`curl_get_droplet | \   R path droplets | \   R find where '{"name": "example.com"}' | \   R path networks.v4.0.ip_address ` ssh root@$IP 'bash -s' < script.sh For simplicity, I replaced exact curl command with curl_get_droplet func

Spikes in RabbitMQ + NodeJS latency test

Image
Measuring things is a fun way to confront assumptions we put everywhere. In software development products tend to be based on tens of assumptions, such as that network will be fast enough, REST or database transaction time short enough, success rate for external API calls within reasonable range. Knowing the limits of those assumptions is always worth at least one beer. The other day I was looking how long it takes my message queue, RabbitMQ, to pass messages from producer to consumer. RabbitMQ has loads of options: queues, topics, durability, acknowledgements, clustering to name a few. It's not obvious how those different options affect latency.  I wrote two little NodeJS processes - producer and consumer, based on samples from RabbitMQ tutorial, to measure how long it takes a message to fly from one process to the other. Those processes would just run many times with various configs to produce data - big latency table. Unfortunately, the very basic scenario turned out to be a

Drawing in Graphiti

Image
It seems Eclipse Graphiti is really popular lately. Germany is using it to build cars, Engineers in India are getting to speed with it as well. Finally I made a try as well and fell in love with the simple APIs and helpful docs. The only thing that struck me is that most diagram editors out there are used mostly to draw just boxes and connections between them. Is that really all you can do!?!?? Ok so you here's what I did, a simple drawing tool in Graphiti: Click below to see it in action! And Fork it on Github Youtube video:

Trouble signing Apps for OSX Mountain Lion

Image
If you're building desktop Apps for OSX, chances are you'll need or you're already working on getting them signed with Apple's certificate. Otherwise your users might see this, starting with Mountain Lion: I just signing few apps and scored new items in my erroropedia: Error 1: "Error signing data" $ productsign --sign 'Developer ID Application: YourCompany' from.pkg to.pkg productsign: signing product with identity "Developer ID Application: YourCompany" from keychain /Users/user/Library/Keychains/login.keychain Error signing data. productsign: error: Failed to sign the product. Reason: keychain is locked for access from SSH. Try security unlock-keychain -p You might also need to enable access to certificate private key for all applications: Error 2: "MyApp.app: object file format unrecognized, invalid, or unsuitable" One solution that worked for me: export CODESIGN_ALLOCATE="/Applications/Xcode.app/Cont

How to create Restful API in Zend Framework 2

Your ZF module just needs to provide Controller that speaks REST (for example RestfulController) and make sure that generated response will be formatted in JSON, in other words configure JSON rendering strategy. Below you can see an example controller. Note that it has convenient methods for to get all elements, single element, create/update and delete an element: use Zend\Mvc\Controller\RestfulController; class UserController extends RestfulController { public function getList() { return array("users" => array()); } public function get($id) { return array("id" => $id); } public function create($data) { return array("created" => "yes"); } public function update($id, $data) { return array("updated" => "yes"); } public function delete($id) { return array("deleted" => $i); } } When associating this controller to route, make sure to NOT use 'action' parameter. Otherwis

Wedding table problem

Here's the old ancient wedding table problem that each man inevitably has to solve on his way to honeymoon. Research on the topic shows that some philosophers simplify this problem to set partitioning problem (not sure if they were on any wedding, or are they just dinning philosophers). Whereas others assign the problem to the social nature of participants. But I guess that for all my readers it's obvious that this is strictly mathematical subject and should be analysed from the algorithms perspective. Problem statement: Newlyweds are holding a party of n guests, where 2m of them comes in couples and the rest comes single. There's one long table with n chairs, split equally on both sides and each guest needs to have a chair assigned. Each couple has to together. Guests sitting next to each other, or on the opposite sides of the table are in talking range. There's a graph G(V, E), where each vertex represents a couple or single guest and each edge represents an acquai