domingo, 22 de diciembre de 2013

Scala I. New years's plan

Over the last years I have been trying to learn one new cool language, but because of my lack of consistency I've been jumping constantly between Erlang, Go and Scala, reading some tutorials, writting some examples... but never getting a real deep understanding of any of them.

It is always good to do plans for the new year, I promise to go for running much more and to read more non technical books, so this year I really want to master one of those languages because I think it is healthy to learn new things, because it is usually a lot of fun and because I think I need it to improve the way I develop software at work.

By the way, I recommend the book Seven Languages on Seven Weeks if you are trying to make a decision like mine.

So, which one to choose....  (spoiler, I have decided to learn Scala).. these are my arguments...

Go is very interesting but who else apart of Google is using Go for serious projects?  In addition it looks like a mixture of python and C and I want something different.

Erlang is really cool and probably the best language/framework for the type of applications I usually build as part of my daily job.   But it is not strongly typed, there are no good tools and doc and it is very difficult to engage people on it.   I tried for the last two months and I give up.

Scala is slightly less cool because it has some Java inheritance, but because of that it is the easier one to introduce in a Java organization.   The language is modern (support for functional programming is basic) and expressive and combined with Akka framework you are close to Erlang features.

So, let's go, hopefully next post will be on some cool Scala feature.

miércoles, 18 de diciembre de 2013

Distributed load testing: Extending locus.io for connection oriented services (2/5)

I have to admit that when talking about testing scripts I'm a python fan because of the simplicity, low overhead and availability of libraries (Ruby could be a good option too).  So, the first think I did when started to build my distributed load testing environment was searching google for "python distributed load testing" and as usual google didn't dissapoint me and that was the beginning of fun with locust!

locust is python testing framework where you write your tests in python and the execution can be scheduled in one or multiple machines.    It has facilities for HTTP testing but can be extended to other services and provides a web interface to get easy access to the progress and results of the tests.

After digging for a while in the documentation (not that good) and the source code (nice code) I decided to give it a try and create my first non HTTP test.   When creating a Locust class (that class defines the configuration of the tests) you can specify a client to override the default HTTP client:

class MyLocust(Locust):
    task_set = MyTaskSet
    min_wait = 500
    max_wait = 500

    def __init__(self):
        super(MyLocust, self).__init__()

        self.client = MyProtocolLocustClient(host=self.host)

class MyProtocolLocustClient(object):
    def __init__(self, host):
        self.host = host
        self.connection = MyProtocolConnection(host)

    def ping(self):
        request_meta = {}
        request_meta["start_time"] = time.time()
        request_meta["method"] = 'MESSAGE'
        request_meta["name"] = 'PING'

        self.connection.send_message(self.connection.id(), "HI")

        try:
            response = self.connection.recv_message()

            if payload != "HI":
                raise Exception()

            request_meta["response_time"] = (time.time() - request_meta["start_time"]) * 1000

            events.request_success.fire(
                    method=request_meta["method"],
                    name=request_meta["name"],
                    response_time=request_meta["response_time"],
                    response_length=0
                )
        except Exception as e:
            events.request_failure.fire(
                    method=request_meta["method"],
                    name=request_meta["name"],
                    response_time=0,
                    exception=e,
                    response=None,
                )



That client object is available to all the locust TaskSets that you will define later with your specific tests.  For example:

class MyTaskSet(TaskSet):
    @task
    def my_task(l):
        l.client.ping()

And that's all, just put that code in a locustfile.py file and run it from the command line:
 locust -f locustfile.py -H xxxx.yyyy.com

And open a browser in http://localhost:8089 to start the test and get the results and you should get something like this:


viernes, 6 de diciembre de 2013

Xamarin and Google Glass together

For the latest weeks I've been playing around with Google Glass, amazing technology!!! and for about a year I've been following Xamarin and using it for small projects/hackathons because I think that it is the PERFECT way to develop mobile apps.   Today it is time to try to use both together!!!

Let's start with some introductions:

Google Glass runs Android 4.0.4 and you can easily run any android app [1]  (thanks song for introducing me to Google Glass world).   You can run any standard android app, Google just released a specific SDK (the GDK) that you can also use with Xamarin if you want deeper integration with Google Glasses.

Xamarin is a cross platform framework allowing you to create mobile apps (e.g. for android) in C#/.NET will using the native UI framework in each platform.

Now, let's start having fun:

1. Download the standard Xamarin package and open Xamarin Studio

2. Create an Android project targeting an android version <= 4.0.4

3. Disable the system status bar and the application title for your Application with this code:
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            RequestWindowFeature(WindowFeatures.NoTitle);


4. Use standard android controls, buttons, textviews...

5. Try to follow google guidelines if you want to create a coherent experience [2]



Screen on Google Glass


I don't have a Xamarin license to create something much better (because of the limitations of Starter licence) but if somebody gets one for me I'll be happy to build something much better to show the powerful combination of Xamarin and Google Glass :)

[1] http://songz.quora.com/How-to-run-Android-Apps-on-Google-Glass
[2] https://developers.google.com/glass/design/index