Parallel Processing in OutSystems

Parallel Processing in OutSystems

  

Quite recently I’ve been task to build a search as you type mechanism with the OutSystems platform. I’m integrating with elastic search so the first challenge was to build a connector using REST services. Luckily, I was able to get my hands on in development version of a connector and that saved me some time.

The first take was quite easy and within a day I had it working.

Then the challenge came. “Can you add another data source?” This new data source is Swifttype (another search engine) and I already had a connector for it so I said “Sure”. I plugged the new connector and did the call and necessary adjustments for it to be transparent to the application. Again, this take was quite easy and I had it working in another half a day or so.

Then a new challenge. “Do you know what would be really nice? To add the knowledge base info into search.”. Fortunately, I already had a connector to that as well but by now it became quite evident that these search sources will probably be increasing in the future.

The more search sources I add the slower it gets and worst the experience of a search as you type will become so I had to come up with a solution. Basically, I decided that I needed to parallelize the requests to each search engine for performance reasons. How could I do it?

While developing OutSystems web applications there are a couple of ways for you to achieve parallel processing.

The first approach is using Timers to do background processing. With this approach, you need to take into consideration that each timer only runs once at a time so if you need to process several tasks in the background you need to create multiple timers that execute the same action but you need to create the mechanisms to control what each timer will process and when to wait for all of them to finish. Doable but tricky.

The second approach is using BPT. BPT is the workflow model of the platform and everything is done asynchronously. You build your workflows using the same low code approach, it’s completely integrated with your applications and allow you to several threads in parallel (5 default but configurable). The catch? Well because everything is asynchronous it’s hard to build a real-time experience plugged into an UI.

What I wanted was the ability to call several actions at the same time, wait for all of them to finish processing and then show the results. Unfortunately, that cannot be done immediately with the platform so I had create a framework that allowed me to do that.

Resorting to c# code and REST APIs I built a framework to allow parallel execution of requests. For each action you want to parallelize you just need to create a REST API that abstracts that action and use the framework to invoke as many requests as you need (the limit is the machine capacity).

This is now built into our search as you type mechanism and we’re still testing it. But I’ve decided that this could be shared with the community as this is a question that some people have already posted.

You can check the demo here and download the Framework on forge as well as the Demo App.

Hi Guilherme,

thanks for sharing this. It might become handy some say.

Cheers,

João