During the WSO2 US Conference 2017 the new programming language for WSO2 products that use mediation and transformation was announced called Ballerina. Ballerinas are graceful, slim, in good physical shape and lightweight. These characteristics are directly tied to their profession. Dancing at that professional level requires a lot from a person and a body.
So, if you call your new programming language Ballerina, you raise the bar for performance. I think that WSO2 is aware of this and they will come up with a graceful, powerful yet lightweight product.
What is Ballerina?
It is an open-source project initiated by WSO2 to foster the development of the programming language called Ballerina and its supporting technologies like IDEs, Debuggers, Testing-Frameworks and so on. Ballerina is not a product but it will be used in the future as a component within products. Although WSO2 is the initiator and main sponsor of the development of Ballerina everybody is free to join and contribute. Right now it is a technology preview currently in version 0.8.3.
However when we look at the support for Enterprise Integration Patterns (EIP) we see that this version does not support all patterns. EIP has been an integral part of the WSO2 ESB and are widely used. As it looks now, the Enterprise Integrator 7.0.0 is the successor to version 6.0.0 and support for EIP is needed in order to migrate from 6.0.0 to 7.00.
This means that before we get to version 1.0.0 things might change and additional functionality will be added. There is no timeline at the moment but we speculate that it will be about a year before we will see a full blown Ballarina language..
Ballerina language is not considered to be a Domain Specific Language; it is a general purpose, modern, concurrent and strongly typed programming language optimized for integration. Although it is a general purpose language the designers of it state clearly the primary domain is integration and you should not be tempted to use it for developing the next high performance 3D renderer. At this moment, Ballerina comes along with an interpreter, but in the future, is planned to compile the code to a binary form (like bytecode in Java). The language is inspired by a variety of languages like the also open source Go language developed by Google.
However, the Ballerina language is open source and its supporting components like the interpreter runtime, the graphical frontends are written in Java which has been the main language for WSO2 products. By that the current runtime can benefit of the entire Java ecosystem and the team is not forced to reinvent the wheel. Anyhow Ballerina is not limited to the Java ecosystem.
Ballerina provides an IDE (called composer) that runs in a web browser. The IDE allows textual, graphical and Swagger editing of Ballerina programs. Core in this case is stability of the IDE. The current graphical environment is, especially for novice users, somewhat unforgiving when switching between source and design, resulting in lost pieces of code. This can be minimalized by for instance saving regularly or not switching so much between two modes but nevertheless can be an area of improvement.
Figure 1 Text editor (source view)
Figure 2 Graphical editor (design view)
Figure 3 Swagger editor (Swagger view)
The IDE gives the possibility to run or debug both models of Ballerina programming:
- application – an application containing main() function (so more like a regular program)
- service – network invoked collections of entry points (more like a proxy or API in the current ESB).
There are also plugins available for popular IDEs like IntelliJ IDEA, Atom, vim, Sublime Text 3 and Visual Studio Code.
Figure 4 Visual Studio Code with Ballerina plugin
To test the new language, we have taken a service we have created in the ESB 5.0.0 and ported it to Ballerina. This is handy because it will give an idea what a migration path will look like because, as WSO2 has also mentioned, migration of current artifacts to Ballerina will be necessary.
The service connects to Yenlo Cars REST API and gets the data in XML or JMS format. The read data are sent to a JMS queue named ballerina.cars.http.
We will explain the functionality by adding comments # in red (keep in mind that Ballerina does not support comments in the source) in the actual program. This is not magic, we just refer to the documentation found online. In all, what we are doing is creating an http message with basic authorization (base64 encoded) and path with a URI template or URI context. We also do a little bit of error handling / exception catching.
The service reads records from MySQL database and returns them in JSON format. All the returned data are sent to JMS queue
Apache ActiveMQ Service
The service reads all messages from the JMS queues named ballerina.cars.* and sends it to the topic
To run this Ballerina service its necessary to copy ActiveMQ supporting files from
$ACTIVEMQ_HOME/lib (used Apache ActiveMQ v 5.14.3):
To run the service
YenloCarsDBService it’s necessary to copy a MySQL JDBC driver jar to
As always it’s expected of new product that it will have good performance and will not consume a lot of memory. It seems that WSO2 Ballerina meets these expectations. During our tests we didn’t observe huge memory consumption.
Figure 5 jconsole overview
We tested access to a HTTP service directly on the local machine and via Ballerina’s service
YenloCarsCountService to compare performance results. We used the gatling.io testing framework. The tests simulate 10 users which call 5 times the endpoints /count, /count/marks and /count/marks/HONDA.
A Gatling simulation to measure the access time to the Yenlo Cars HTTP service directly running on local machine.
A Gatling simulation to measure the access times to the Yenlo Cars HTTP service running on local machine via a Ballerina service.
The results are nearly the same. As presented on the Gatling overall simulation report the response times are nearly the same in the standard ranges. We see on chart that for 50 requests, we get the response in the time less then 0,8 second. The rest of requests have response in the time more than 1,2 seconds. The standard statistics such as min, max, average, standard deviation and percentiles globally and per request presented in table also contains nearly same values. In average the difference between request per second is 0,02.
Summarized the test, we didn’t observe that accessing the endpoint directly is significantly faster than via the Ballerina service. Please bear in mind that
ServiceLocalhost only gets its data from the HTTP REST endpoint and the
BallerinaService also sends its data to ActiveMQ.
Figure 6 ServiceLocalhost results
Figure 7 BallerinaService results
We see that Ballerina already can connect to backend services like the Yenlo Cars API and that it produces results.
However, as stated in the beginning, it is a technology preview. That means that it is not finished yet and the community is working hard these days to push the language towards the 1.0.0 version.
To sum up our comments:
- The Ballerina product still in development. Missing right now some implementations, like null keyword or comments in code.
- The Ballerina language simplifies interaction with an external system or a service you’ve defined in Ballerina. Interaction with HTTP/HTTPS v1/v2, JMS, WebSocket and FTP/FTPS/SFTP is very simple using build-in connectors. Also access to databases very simple using a connector.
- The language is simple, but for Java developers can be missing OOP functionality like inheritance (is-as) or some language syntaxes like ?: or for(…);
- XML and JSON are first class citizens in Ballerina. Which is just great because both of them will be around for quite some time in the future.
- The Ballerina language seems to be a nice tool to integrate services and platforms
- We’re missing the capability to #comment the Ballerina Code.
- Surprisingly one cannot execute a program with unused imports (clean code?)
The listed in article Ballerina examples are available on Bitbucket.
If you have any questions about this blogpost contact us via the comments section of this blog. For more View also our WSO2 Tutorials, webinars or white papers for more technical information. Need support? We do deliver WSO2 Product Support, WSO2 Development Support, WSO2 Operational Support and WSO2 Training Programs.
Thanks to Jochen, Rob and Thijs for their contribution to this blog.