Tuesday, March 31, 2009

Erlang

I'm grouping all three readings into one blog post because they're all perspectives on the same thing.

Problem: Writing reliable, scalable, industrial-grade distributed systems. Not an easy problem! And it's definitely real and becoming realer for more types of applications.

Solution/Nugget: Erlang has a lot of interesting features, but the main idea is to give you a more restrictive programming model provides good primitives for writing distributed apps but makes it hard to get into trouble. In other words, some tasks are easier if you tie one hand behind your back.

The actual model chosen by Erlang is actors communicating by asynchronous messages at the high level, and functional programming within an actor. The use of functional programming makes it easy to manage memory and prevents the programmer from getting into trouble with shared state (since variables are read-only). It's also nice for making program shorter, although Erlang syntax has problems too (see below). The use of actors makes it possible to treat different request handlers / etc as different entities in the program while sharing a small number of physical threads (kind of like the lightweight threads in Cappricio). It also real models networks directly, as messages may get lost, reordered, etc; applications or libraries can choose how to handle these cases. Most importantly, actors are independent units of failure. Along with Erlang's error reporting and process supervision mechanism, this lets multiple modules with potentially buggy code coexist within one runtime and survive crashes of some of the actors without taking down the entire system. The use of message passing and functional programming is also what makes it easy to do garbage collection and runtime code replacement, because the interfaces between executing processes are clean.

Why is the solution different from previous work? It actually works: people have built large systems with many nines of availability out of it. This derives from the fact that Erlang started out in a very reliability and scalability conscious environment -- a telecom -- and added a minimal set of features to make programming distributed systems easier. The result is a language that might not fit nicely into most traditional programming paradigms (it's not really purely functional for example) but gets the job done. Most importantly, Erlang takes into account "production" issues like code replacement and isolating failures that many academic systems don't because academics are not as aware of these issues.

Fundamental tradeoffs: In designing programming languages, there seem to be two related tradeoffs:
  1. Performance versus conciseness: Languages with high-level programming features like functional programming, dynamic typing and pattern-matching generally can't perform as well as languages that give you direct access to memory and an easy way to map your program onto CPU instructions. However, they do give you conciseness and as a result more debuggability and testability. Erlang opts for conciseness.
  2. Range of features versus reliability/predictability: Both high and low level languages can have broad or narrow feature ranges. For example, C++, a "low-level" language according to the definition above, nonetheless allows all kinds of programming paradigms (OOP, functional [sort of], procedural, generic, etc). Ruby, a more "high-level" language, also offers all of these. These languages seem great when you learn them because they let you use a wide range of programming styles, but in doing this, they give you more opportunity to shoot yourself in the foot and they also become very hard for compliers and runtimes to analyze. In contrast, Erlang is a high-level language with a restricted feature set. The restrictions make it easier to debug Erlang programs and to run them reliably, at the cost of removing some programmer flexiblity. SQL is another high-level language with restricted feature set, although it doesn't have quite the predictability benefits of Erlang because it is declarative. I actually don't know any low-level language with restricted feature set but the way Google uses C++ for example is to restrict usage of the crazier/harder-to-debug features.
The interesting conclusion from this taxonomy is that it isn't just a three-way tradeoff between performance, abstraction and predictability. Abstraction can be both helpful and harmful for predictability. In the Erlang case, it's helpful, but in SQL, which is also very abstract, it's hard to predict performance. This is why I tried to split up abstraction into conciseness and range of features, although these aren't great terms for the distinction I'm trying to make.

Is it influential? Yes, people at Amazon, Facebook and other companies are now using Erlang for web systems. New high-level languages like Scala also support Erlang's concurrency model.

Criticisms: While Erlang is a very neat system, it's also 20 years old, and some of the design decisions are really weird. In particular, Erlang syntax can be unnecessarily restrictive, and Erlang string processing is really inefficient because strings are represented as lists of 32-bit integers. This post by a CouchDB developer does a great job explaining Erlang's limitations. So does Chris Newcombe's presentation on Erlang.

Sunday, March 29, 2009

X-Trace

Problem: Collecting traces of applications composed of distributed components in different administrative domains. Is it real? Yes.

Solution/Nugget: Pass along just enough metadata to form a task tree, but log all trace events locally within each AD. One can then reconstruct the tree after the fact.

Why is it different from previous work? Mostly because it changes the problem by trying to work across ADs.

Tradeoffs: There seems to be a tradeoff in all tracing work between the amount of code modification required and the value of the information captured. One interesting thing here is that it might be possible to instrument a few middleware libraries to capture a wide variety of behavior (this is what Andy and I did with Hadoop). However, doing this for all existing apps is difficult. It might also be interesting to combine X-Trace with existing libraries/tools like log4j or DTrace and let those fill in some nodes on the DAG of events.

Will it be influential? Probably; there are signs that Microsoft and Google have similar systems.

Criticisms: It might have been nice to specify a formal X-Trace format in this work, to make it easier for applications to adopt it. George and Rodrigo have done this now, but if the paper had "productized" X-Trace a bit more, more apps might have been running it now.

DTrace

Problem: Instrumenting production systems to find performance issues while the system is running. Is it real? Yes, everyone has this problem.

Solution/Nugget: D-Trace provides a uniform, extensible API for instrumenting both kernel and user level behavior, letting the same tracing program access both. The D programming language for tracing scripts is also a novel contribution because it supports high-level programming constructs and easy access into kernel variables while keeping tracing code "safe".

Differences from previous work: D-Trace mostly differs because it combines a number of good ideas and good engineering practice. There were other systems that did particular pieces of D-Trace, but D-Trace managed to combine these into a single framework upon which a lot of instrumentation can be built.

Tradeoffs: There are certainly some tradeoffs mentioned between tracing performance, safety and power to collect data. D-Trace tries to enable the most types of analysis while providing strict guarantees for performance and safety. The language contains constructs like aggregates to make this easier.

One other aspect, which may or may not be a tradeoff, is that D-Trace is designed to be an "interactive" tool where you write a trace program for just the events you care about and run it. Other systems, like X-Trace, try to be a "capture" tool where you analyze data after the fact. This makes D-Trace fast and flexible but means that it cannot be used for post-mortem analysis of a problem. This is why the paper focuses on performance problems mostly (which occur chronically).

Will it be influential? Hopefully. It would be really great to have this as a standard API in Unix-like OSes. Right now D-Trace is one of the main advantages of using Solaris but can't be used in Linux because the license conflicts with the GPL.

Wednesday, March 18, 2009

Artemis, Chukwa and Scribe

I'm going to talk about these three together because they are very similar and need to be compared against each other. All three are frameworks for log collection and analysis in a data center.

The first difference is in the latency of analysis. All three frameworks are used primarily for offline analysis, but Scribe also supports close-to-realtime routing of messages through various servers. (The other two have some modules that scan files periodically and are therefore intrinsically higher-latency.) It seems that in general, anything based on monitoring files might be higher-latency and less aware of message boundaries than a system like Scribe where the app actively pushes messages.

A second difference is in pieces of the analysis stack provided. The articles jointly identify four components needed for log analysis:
  1. Some source of data (new instrumentation library in Scribe, or just collecting log files from existing libraries in Chukwa and Artemis).
  2. A system for collecting the logs centrally.
  3. A system for storing the logs.
  4. Analysis tools on top of the collected logs.
Artemis provides all four components, although 1 just uses existing logs. Chukwa provides 1-3 but lets you build 4 rather than attempting to have as detailed a library as Artemis. Scribe really only provides 1 and 2, and in fact requires you to do the plumbing for 1 if you want to use external data sources. The interesting thing however is the commonality in how the articles suggest you do 3 and 4 -- they all talk about using Hadoop or Dryad if your scale is sufficiently large. Unsurprisingly, log analysis is a good use case of Dryad and MapReduce.

Monday, March 16, 2009

Google Apps Security Review

This is a pretty serious document aimed at reassuring Google Apps users about the security of the services. As such, it probably contains a little bit of marketing on top of the technical content, but it's still very interesting to read to see all the issues they care about. This is certainly one of the most enterprisey documents you see from Google.

The document talks about multiple aspects of security, including physical security, data security, privacy, organizational/operational security (how the organization is designed so that security gets built into apps), and threat evasion (dealing with security problems when they do happen). The most interesting parts to me were the ones about development methodology: all new developers are trained about security (I went through some of this myself when I interned at Google), and all products are audited throughout the development process. The document rightfully points out that security must be designed into an application from the beginning and carefully managed thereafter; it can't be bolted on or "validated after the fact". Also interesting is the part about Google developing its web servers etc to only contain the outwards-facing features its apps need, rather than using something like Apache. This is a good way to make the code smaller and more auditable.

One of the points I didn't agree with was about Google's internal infrastructure making it hard to find user data even if someone does break in - for example, because data is distributed among multiple servers. I find this hard to believe. If someone breaks into the Google intranet, they also find all the developer documentation including API docs on how to read/write data from the storage systems. They can use these to find the relevant data. This argument sounds to me like security through obscurity. I'm sure however that there are other systems on top of the infrastructure that provide more protection beyond hoping that someone just won't figure out where the replicas of a given block are.

Azure Writeups

These writeups do a good job explaining the components of Azure, although they still leave many questions annoyingly unanswered. There seem to be four components:
  • Windows Azure: runs applications in an EC2-like manner. There seem to be two types of apps allowed (both .NET for now): "workers" which do background processing and "web" apps which serve requests. This immediately seems kind of restrictive, but it also gives Microsoft good hints about how to automatically scale up and manage these types of apps. I'd really like to see the APIs and development environment to better understand what can and can't be done with these two roles. I imagine some of the APIs are pretty neat.
  • .NET Services: hosts web services for use in your own apps and in other peoples' apps.
  • SQL Services: Azure's storage service, for now just a simple pseudo-relational database similar to Amazon SimpleDB. It will be interesting to see what else they add (data warehousing? something with fuller SQL?)
  • Live Services: Mostly seem to be a way to tap into Microsoft's Live web properties as well as its desktop mesh technology for connecting devices. This section of the paper was hard to extract useful information from since it was vague and somewhat full of marketing speak. The impression I got though is something like Facebook Connect or Facebook Apps, which lets apps interact with users' data within some structured environment. This is a pretty good idea even though it's not entirely clear right now how well Live will do.
In general, the advantages of Azure seem to be higher-level API (with a corresponding disadvantage of less developer freedom than EC2) and better integration with tools. I don't doubt that for certain key classes of apps, Microsoft's team has done serious user studies and planning to figure out how to let businesses use the cloud. The interesting question however will be whether Azure will have the same level of third-party developer energy going into it as the open-source-powered EC2. Projects like Hadoop for example are already supporting integration with EC2; it's very hard to imagine such projects running on Azure because they bring in dependencies on other open-source software (Java, Linux). Microsoft does have some great technology groups internally, but will those always be able to keep up with the experience and development effort of the open-source ecosystem?

Cloud Architectures / GrepTheWeb

This is a really interesting piece on how to build software for a cloud computing environment. The paper not only talks about a real example but extracts the nuggets for us so it's very easy to write about. They are:
- Make all pieces of the system scalable and, when needed, parallel.
- Make the pieces loosely coupled (their use of SQS is a great example).
- Launch things on demand (it's especially easy for their non-realtime query service but it's a good thing to aim for in all services).
- Be resilient to reboots and restarts (basically ROC).

All these ideas make sense. I think none of them is really novel, but it's great to see them combined together.

Beyond this, there are also some really useful tips about how to use SQS, S3, etc for maximal efficiency, which I imagine cloud users will find quite helpful.