Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Friday, June 1, 2012

Looking at JSON-RPC


The JSON-RPC spec has been around for some time now (since 2005) though I have only just recently become aware of it. The moment I saw It, I thought “brilliant!” just at the site of its name.  After looking into it further I am surprised at how very simple it is… and it doesn't need to be more complicated.  It makes it quite easy to write servers and clients in most languages.  This fits right there into one of the latest trends in software engineering which is polyglot programming or using multiple languages in a system to accomplish tasks using the best tool for the job.   It also fits in to a distributed programming model as well.
The JSON RPC specification doesn’t require a specific transport mechanism; I implemented it over HTTP using scala as an example implementation on both the client and server sides.  One benefit of using HTTP is that you can use JavaScript to remotely call a JSON-RPC methods. The implementation could use other transports such as AMQP or many others.

The request
Requesting a remote invocation is easy; simply send a message that looks like this:

{
      “method”: “echo”,
      “params”: [
            “hello”
      ],
      “id”: 1
}

While this is fairly self explanatory, it’s important to note that if the “id” is set to null  The request becomes a notification which is specified to have no response.  Otherwise, the “id” field should be used for message coordination on the client side.  The “id” can be of any particular type that is valid in a JSON message.

The response
A response to the message posted above should look like:

{
      “result”: “hello”,
      “error”: null,
      “id”: 1
}

The response is also quite self-explanatory.  Every response message must contain the “id” to the corresponding request message.

Additional Notes
A generic client should not make any assumptions about message order when using a streaming connection.  Responses may come back in a different order than the requests that came in so use the “id” field to coordinate the messages.

Clients should pay attention to protocol specific errors to handle them accordingly.  If a client is using the HTTP protocol there are a number of java/scala exceptions that may be thrown in the process of establishing a connection which are outside of the “error” field.

Clients and servers should validate the JSON messages and handle errors accordingly.

Security must be implemented at several levels.  The transport level will include encryption as well as authentication.  As always, all input data should be validated and checked to avoid injection, XSS and other known vulnerabilities.  The frameworks you use may not always validate the data you will be dealing with.

Overall, I like the specification, it is simple and easy to use.

Tuesday, April 24, 2012

Data and Persistence

For a while, I was fairly sold on JPA/ORM technologies.  I thought great, I can work with Java Objects and they will magically be stored in the database... Well sort of and that works great for a lot of cases, especially where there is only one database involved or even one type of database involved like say a Relational Database.  They can really save a developer a lot of time and frustration.  But what happens when you want to start making use of some of the non relational databases?  NoSQL (Not-Only SQL) has been driving the industry to consider alternate ways of storing information, not to mention that there may be Cloud based options to store data outside of NoSQL and traditional databases.

To add insult to injury, some of the ORM frameworks (Hibernate?) have become over-burdensome and bloated.  It has been said that all frameworks have holes in them and ORM is no exception. I trend towards light-weight solutions that suit my needs, sometimes ORM is the right answer.  The push to NoSQL really comes from an operational need to perform at "Web-Scale" that is companies like Facebook, Google, Amazon, Twitter to name a few.  These companies deal with a tremendous amount of traffic that outpaced the relational database strategies they were using. Even a number of smaller start-up companies deal with high traffic volumes and large amounts of data.

It makes sense that when developing a solution to consider using NoSQL for certain portions of your system.  Even with the industry hype about the latest NoSQL products, there seems to be a shift back to improving SQL to meet high traffic demands.  It also seems that the industry is starting to figure out the best fit for specific database systems, realizing that SQL is not always the answer but neither is NoSQL we now live in a Polyglot world of data persistence.

Some advice, make sure you don't use a NoSQL database without researching and understanding where it excels and where it is lacking.  Using something because it works great for some project and you want it too isn't a good enough reason.  Look at your requirements, your team's abilities, and where the application is headed in the future to make a good decision about what tools you will use to persist your data.  As with any technology, try not to just jump right in with a new product, try to ease it in through smaller projects to gain experience and understanding of it before migrating larger systems.

Wednesday, April 4, 2012

First OpenStack Experience


I’ve been monitoring the OpenStack project quite casually since it first started and finally the other day I found enough time and motivation to start playing around with it.  I thought I would document my initial experience with the platform and I hope that others find this information valuable if they run into some of the same issues I did.  One caveat to this article this is I'm a software engineer, not a Linux system administrator.

Fortunately I have the luxury of having a fairly high powered computer on hand on which I loaded Ubuntu 11.10 on the spare disk.   In my first attempt at installing OpenStack, I managed to install the 32bit version so once I got up and running and I was momentarily confused about why I could only spin up “m1.tiny” instances.  This error gave some great experience in understanding how to setup OpenStack so I re-installed the laptop with 64bit Ubuntu and I made sure that I re-partitioned the drive so I had enough free disk space for the “nova-volumes” LVM group required by swift.  (As a note, in the first installation attempt, I created the LVM volume “nova-volumes” in an image connected to /dev/loop1 since I didn’t have a free partition at that time.  This strategy was effective for my purposes)

The guide I followed to install OpenStack can be found here: http://docs.openstack.org/trunk/openstack-compute/starter/content/.  This guide is quite detailed and provided a lot of really great tips.  Excellent job OpenStack team!

The main place I ran into trouble was with running the custom AMI image that is created when walking though the guide, described http://docs.openstack.org/trunk/openstack-compute/starter/content/OS_Installation-d1e1298.html .  The process of creating the AMI worked well enough and the image does run but there seems to be several problems. (others may not experience this)

  • cloud-init does not seem to run properly even though I have access to http://169.255.169.255/ I don’t know if this was my setup or if I am missing something with the installation and setup of cloud-init but it does not properly set my ssh keys or my host name of the guest os.  I can ssh to the guest and login with the user-name and password created in the installation process.  Running an Ubuntu cloud AMI from http://cloud-images.ubuntu.com/releases/oneiric/release/ works great, cloud-init performs its functions, sets up ssh keys, sets the host name, runs scripts etc… so clearly I’m doing something wrong when I create my custom ami but I’m happy running the Ubuntu images for now.
  • When I tried to attach a volume to my custom AMI, the euca-attach-volume command would return successfully but the OS did not recognize it.  After a lot of frustration I realized that I could attach the volume and then reboot the instance before it would show up.  I still don’t know why this is the case however, the Ubuntu cloud AMI’s work well here too.  They immediately detect when a volume has been attached / detached.
I don’t know where the tutorial for creating a good Ubuntu AMI is, I did look, but I didn’t look that hard so maybe if I am motivated I will solve this problem as well.

The other problem I had was also related to attaching volumes.  The tutorial states that open-iscsi is always used when attaching the volume which is almost true, there is a flag that allows for a local drive to be used when swift and compute are both installed on the same server (which is my case).  So as part of the debugging process when I was trying to figure out why everything looked good but no volume was attached to my image, I saw no ISCSI connections when running ‘sudo iscsiadm –m session’.  Eventually I found the flag and disabled local connections and ISCSI was discovered properly which is where I ran into my second problem which was that ‘lun-0’ was hard-coded into the OpenStack ISCSI volume driver code for attaching the ISCSI drive to the instance and, of-course my swift-created volume was on ‘lun-1’.  I fixed the code (hacked the code hardcoding ‘lun-1’… bad I know) and then everything was working well. After reviewing the code on GitHub I realized that the OpenStack guys are already on top of the issue and have since addressed it and in fact, it seems that they have addressed a large number of issues in the current code base that would still be in the packages installed by Ubuntu 11.10.  That said, I have not upgraded since everything is currently working just fine.  I could have simply relied on the local drive instead of using ISCSI but I didn't realize that was working until after I made the changes to my local installation.

I briefly tried installing keystone and dashboard but the documentation was not easy enough for me to follow in a couple of minutes so I aborted configuring those projects.  I will probably re-engage those projects when they become part of the OpenStack core but I don’t really need them for my current experimentation.

In conclusion, OpenStack is a great project, my adventures with OpenStack are far from over and I have learned a ton about it and in general the cloud platform with respect to Amazon AWS and Rackspace.  I still have a lot to learn about the platform but I can get by with the basics now.  This is a pretty powerful technology and having access to a private cloud is an important thing for me.

Monday, April 25, 2011

Amazon AWS

It wasn't until it failed late last week that I realized how much of the web depends on Amazon.com's AWS services.  I have actually been planning on using AWS on an upcoming project so I read the news on it's failure with great interest.  This event does not scare be into not using Cloud services to deploy a new site but it does shed new light on the fact that even though your deploying an application to the Cloud, you still have to design the system for failure event within a Cloud data center.  I suppose that is really nothing new, the concept of disaster recovery has been around for a very long time.  I think that a lot of folks who deploy to a cloud computing environment don't consider that since it has more or less been "sold" to us that the cloud takes care of that.

Sunday, March 21, 2010

Scalability

Over the last few days I have began to do research into scalability.  Something about scalability is very attractive to me and a number of other folks.  It's quite impressive reading about some of the things that Amazon.com, Facebook, Google, and a handful of other sites have been doing with regard to scalability.  These sites have unique challenges because their user base is continually logged in which means the site must fetch user account data along with a number of other custom, account specific information to generate a page.  Traditional techniques for scaling a website don't necessarily work well for these applications. That being said, for a number of years now the trend has been steadily moving toward web applications verses Desktop applications.

So what exactly is Scalablity?  Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be readily enlarged.  So in order to achieve scalability for a given system an Engineer must evaluate the paculurarities of their system to find what solution will work best for their on going needs.

Reverse Proxy

A reverse proxy is a proxy server that helps out a web server by providing content out of a cache which can be retrieved quickly thus reducing the load on a web server or an application server.  This technique is used by many websites to help them scale up and handle more requests with fewer hardware resources.

One of the more popular proxy servers out there is Squid.  Squid's competency is to provide a proxy-cache which will not only act as a middle man between the web and a web server but it will also cache server resources so to provide them up quickly on consequent requests.