Community

MarkLogic 10 and Data Hub 5.0

Latest MarkLogic releases provide a smarter, simpler, and more secure way to integrate data.

Read Blog →

Company

Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up →

 
Knowledgebase:
Techniques for dividing tasks between hosts in a cluster
09 May 2018 05:43 AM

Introduction

This article will outline a general strategy for distributing a specific task across every node in a server.

There are situations where you would like to execute queries against a number of hosts in a cluster - one such example would be to break a query down so it only operates on the forests on that particular node. Using the patterns described in this article, you will be able to build a mechanism to do just that.

The problem

Wouldn't it be useful if you could pass in options into xdmp:spawn() to allow the execution of code on a specific host in a cluster?

While this has been filed as an RFE (2763) for consideration in a future release of the product, there are a few options open to you.

From the top down

1. Gather information about each host in your cluster

For this you can use a call to xdmp:hosts(). This will give you a sequence of host ids - each corresponding with a node in your cluster. From here, you can get the xdmp:host-name() The snippet below demonstrates this: