Jul 27

Sending Messages to Slack From Go

Slack is a great communication tool for teams of international developers who need to keep in sync. I personally use it every day and I find it to be much better than some of the other alternatives out there. While working on another project, I came across the need to send notifications to Slack from my Go application. Utilizing Slack’s awesome API, I wrote a quick package to easily send messages to a Slack channel.

GoSlackOff was born! To use it, simply create an instance with your Slack username, hook token, the default username to post as and the default channel to post in:

And then call the  SendMessage()  method. You can also override the channel or username for each message.

The SendMessage()  method will return a success boolean and the HTTP response object from the API call.

For more information, check out the README on github!

May 5

Titanium Alloy as a mobile platform


Back on track now after the last, somewhat off-topic, blog post! Today I want to talk about a new platform I’m using for work called Titanium. What it does is it allows you to create fully native mobile apps using JavaScript as the language.

Why this? Why now?

Well, it’s not the first framework to provide cross-platform development tools for deploying the same codebase across multiple devices. Phonegap has been doing that for years! And up until very recently, Phonegap has been my go-to-guy for easily creating mobile applications without the nightmare of Objective-C based programming or even worse, Java based coding. What happened was I had just finished programming the app for iOS; it looked beautiful and it functioned perfectly. Transitions were smooth, pages loaded quickly, basically everything was awesome.

Sure enough, when I go to port it over to Android to make sure it works the same, it doesn’t even look remotely the same let alone function properly. I was getting probably 2fps max on page transitions on top of the already ridiculous 5 second delay between a tap on the screen and a reaction of any kind from the UI.

I was disappointed and frustrated. I had just spent the last 2 months building this beautiful app on iOS just to have it look and function like crap on Android. So, after many long hours of research and some help from some friends, I found Titanium (actually my friend had mentioned it a while back but I forgot about it :P).

So far so good!

I’ve been using Titanium for a week now and all I have to say so far is that it is amazing. You get the performance and the feel of a native app, all while maintaining that cross-platform portability that Phonegap brought to the table. The best of both worlds I think! It’s incredibly easy to use and the results outperform any Phonegap or “hybrid” application out there.

I’ll be working with Titanium for the rest of this week and I will post another blog post shortly with some thoughts :)

Dec 16

Multithreaded Socket.IO Server

Turbo charge your NodeJS applications with Multicore

Recently, I’ve been developing a new chat/messaging platform for my site, DarkUmbra.net that will be used throughout the website as well as for upcoming mobile applications. I started running into issues first with the linux kernel killing my chat processes because of open connections but after increasing the ulimit that issue subsided. Because of these crashes, I began looking for a way to run the chat on all 8 cores of the system to optimize performance and add redundancy in the case that one of the worker processes fails.

As you all know, NodeJS only runs on a single thread on one core of the server it’s running on by default. However, it comes installed with a simple utility that allows you to fork extra processes/workers as desired that can all access the same port/server running on Node. This is an incredibly useful feature and I recommend that everyone migrates their applications to multicore as it easily octuples (is that even the right word? Lol) the performance of the application. To illustrate this, I performed some ab benchmarks on my local installation which just served up which worker ID it was connected to. The test was to perform 10,000 requests and the results were really encouraging.

On the single core machine, the test took 4.503s. The multicore server however completed the test in 3.376 seconds, more than an entire second quicker; and that’s just running on my MacBook Pro. Throw in some server-grade hardware and wow does it fly. I’ve posted the Apache Bench results below for those who want to see the full output.

Now multiply that 1.1 second savings over 1M requests and you’ll quickly see the performance increase is exponential! Here’s how to do it:

What you Need

Scaling to Multicore

Let’s start with the basic file:

Configure the Master Process

Now that we have the basic structure that will control both the master process and the worker processes, let’s setup our master process. To make sure socket.io can talk to other socket instances on different workers, we have to configure them to use a Redis Store. Thankfully Socket.io comes packaged with Redis already so we don’t have to install it separately, simply tell socket.io that you want to use a separate Redis server. Let’s add this inside the if( cluster.isMaster )  if block:

Create Workers

Time to create the additional processes that will the server simultaneously. This can be done manually by calling  cluster.fork() as needed, but I prefer to spawn one process per CPU core:

Deal with Worker Crashes

Sometimes an exception will occur that is uncaught by your application causing your server to crash. When this happens, normally the application itself terminates. However, since we are running a multithreaded environment, we can detect a worker process has died and restart one in it’s place:

Adding Worker Code

Now that we have our Master process all set up to create worker processes, let’s go ahead and add some worker code to run on the threaded processes. Working now from inside the if( cluster.isWorker )  if block, let’s configure the server and the Redis store like we did before, this time, we’re going to add an extra line to start the server listening on the port:

Add Socket Bindings

Realistically we’re all good to go now, but our server doesn’t actually do anything yet. Let’s add some simple socket.io bindings:

That’s It!

If you start the server up, you’ll now see something like this:

Multithreaded Socket.io Server

Multithreaded Socket.io Server

There you go! Your server is now running socket.io in full multicore mode! If you wanted, you could even get fancier and spawn more workers as processor load increases and then kill workers off as the load goes down 😉 But I’ll leave that to you 😛

As always guys if you have any questions or comments, post ’em below and I’ll do my best to answer them :)

Apache Benchmark Results

Aug 22

Copy – The New DropBox

Copy Banner

There are dozens, maybe even tens of dozens of online cloud storage services that offer free online hard drives for people to dump their stuff to and share it with people. Dropbox, Google Drive, SkyDrive, etc… All free, all secure, all share-able. Copy is the new kid on the cloud storage block and they’re bringing out all the big guns. For starters, they offer you 15GBs of space right out of the box. Google drive up until very recently only gave you 5GBs (they now offer 15GBs), Dropbox even less at 2GBs. So Copy beats Dropbox by 7 and a half times… and ties with Google. Unless of course you are referred by someone in which case you start out with 20 and then you beat Google by 5 =P So tell me, why wouldn’t you?

Naturally all these services have the option to invite some friends and get more space but again, Copy trumps all. For a limited time (they don’t say how long), Copy will give you and a friend 5GBs of extra space for every user you refer. That is to say that anyone who signs up through your link starts out with 20GBs out of the box!

Copy.com Huge amounts of free storage

Copy – huge amounts of free storage

Now I’m not posting this just to spam invites out of people… I’ve already invited a bunch of people through Facebook, my forum DarkUmbra, etc etc so the real purpose of this post is to attract the attention that Copy deserves. It is a killer service, with full apps on phones, tablets and it is putting other cloud services like Dropbox to shame! I’ve jumped ship and I advise all of you to as well!

Claim your 20GBs of FREE cloud storage on Copy.com and I promise you you won’t regret it =)

And no, they didn’t pay me to write this or anything lol… it’s just a killer service and I love them =P

May 4

Neat NodeJS Plugin


I found this neat plugin today for Node.js development called Nodemon. What it does is it monitors the files you’re working with and restarts the server whenever a change is made. This will be particularly useful for those who are sick of hitting CTRL + C, UP ARROW, ENTER each time they save a file. On top of that, if some change is made to the script that causes it to error and crash, Nodemon will display the error and wait for you to fix it before restarting. This prevents infinite looping if errors occur!

To install Nodemon, just use the built in Node Package Manager, npm

Once it’s installed you can run it as you would normally but substitute the node command with nodemon so nodemon some_application.js. As an added bonus, cd to your work folder first so it can monitor all folders and files of your application.

I found this to be exceptionally useful during development and saves a lot of time!