# Load balancing multiple writers

**URL:** https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407
**Category:** Google Groups archive
**Created:** [April 26, 2021, 6:54am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407 "2021-04-26T06:54:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![diegovictorbr](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/diegovictorbr/32/1586_2.png) [@diegovictorbr](https://discourse.orthanc-server.org/u/diegovictorbr)
#### Post date: [April 26, 2021, 6:54am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/1 "2021-04-26T06:54:24Z")

</div>

Hello.

Since the new 1.9.2 Orthanc release I was wondering about how one could implement a load balancer for multiple writers listening through DICOM. Is that possible with the DICOM protocol or only with DICOMweb?

---

<div class="post-metadata">

### Author: ![James\_Manners](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@James\_Manners](https://discourse.orthanc-server.org/u/James_Manners)
#### Post date: [April 26, 2021, 7:01am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/2 "2021-04-26T07:01:02Z")

</div>

Hi Diego,

You could use NGINX to act as a tcp load balancer ([https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/](https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/)). I know you can use NGUNX to proxy a simple dicom connection but have not tried it to load balance the connections. Give it a go and let us know how it goes.

There are other proxys you could use use as HA Proxy or Traefik.

James

[![Binary Logo](https://binary.com.au/assets/e-binary.png)](https://binary.com.au/)

**James Manners** • Director  
Suite 3, Level 2, 10 Queens Road, Melbourne, Victoria 3004, Australia

T: 03 9017 5230 M: 0422 973 235 E: [james@binary.com.au](mailto:james@binary.com.au) W: [binary.com.au](https://binary.com.au/)

---

<div class="post-metadata">

### Author: ![diegovictorbr](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/diegovictorbr/32/1586_2.png) [@diegovictorbr](https://discourse.orthanc-server.org/u/diegovictorbr)
#### Post date: [April 26, 2021, 1:48pm UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/3 "2021-04-26T13:48:45Z")

</div>

Hi James!

I set up a test environment with Docker similar to what i already have in production. Since the NGINX Docker image comes with streaming support out of the box, it was easier than i expected.

However, i have seen no significant improvement in storage times with this new setup. I compared the storage times of 11 studies sent all at once (8 CRs, 1 DX, 1 CT, 1 MR) between 1 writer Orthanc and N writer Orthancs architecture  
The times always ranged between 5~6 minutes with the **1 Orthanc architecture being faster**. Since it was a quick test, maybe i forgot some important configuration.

Anyway, here is the source code of the test project (created with Docker Compose). It is attached on this post.

The tests were run under Docker on Windows 10.

[multiple-writers-test.zip](https://discourse.orthanc-server.org/uploads/short-url/luCRLi1lEwZj9o9YYgQDY6l26a4.zip) (4.39 KB)

---

<div class="post-metadata">

### Author: ![diegovictorbr](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/diegovictorbr/32/1586_2.png) [@diegovictorbr](https://discourse.orthanc-server.org/u/diegovictorbr)
#### Post date: [April 27, 2021, 9:43pm UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/4 "2021-04-27T21:43:37Z")

</div>

I thought about routing incoming studies to different modalities based on their type (CR, DX, etc). The problem with routing is that i can only send the instance to another modality when it is already stored on the first one.

And since C-STORE doesn’t have headers identifying the modality, NGINX can’t decide anything besides the least\_conn setting.

---

<div class="post-metadata">

### Author: ![diegovictorbr](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/diegovictorbr/32/1586_2.png) [@diegovictorbr](https://discourse.orthanc-server.org/u/diegovictorbr)
#### Post date: [April 28, 2021, 3:53am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/5 "2021-04-28T03:53:30Z")

</div>

I was looking at ReceivedInstanceFilter, but I couldn’t find a Python equivalent event. I don’t know but i could use that event to send the instance to an Orthanc writer peer and reject the instance returning false. I will get back when i have some results on that.

---

<div class="post-metadata">

### Author: ![jodogne](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/jodogne/32/1511_2.png) [@jodogne](https://discourse.orthanc-server.org/u/jodogne)
#### Post date: [April 28, 2021, 5:35am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/6 "2021-04-28T05:35:41Z")

</div>

The “OrthancPluginRegisterIncomingHttpRequestFilter2()” primitive of the C/C++ SDK corresponds to Lua callback “ReceivedInstanceFilter()”:  
[https://sdk.orthanc-server.com/group\_\_Callbacks.html#ga49e34b40e43b222031540ea305246e3f](https://sdk.orthanc-server.com/group__Callbacks.html#ga49e34b40e43b222031540ea305246e3f)

This C primitive is not automatically mapped by the code generation using Clang, but could certainly be manually wrapped:  
[https://book.orthanc-server.com/plugins/python.html#overview](https://book.orthanc-server.com/plugins/python.html#overview)

In the meantime, consider writing a C/C++ plugin:  
[https://book.orthanc-server.com/developers/creating-plugins.html](https://book.orthanc-server.com/developers/creating-plugins.html)

Sébastien-

---

<div class="post-metadata">

### Author: ![jodogne](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/jodogne/32/1511_2.png) [@jodogne](https://discourse.orthanc-server.org/u/jodogne)
#### Post date: [April 28, 2021, 5:37am UTC](https://discourse.orthanc-server.org/t/load-balancing-multiple-writers/2407/7 "2021-04-28T05:37:16Z")

</div>

Sorry, typo, I was referring to “OrthancPluginRegisterIncomingDicomInstanceFilter()”:  
[https://sdk.orthanc-server.com/group\_\_Callbacks.html#gafc862afa442d59adbb9affc8b7f51773](https://sdk.orthanc-server.com/group__Callbacks.html#gafc862afa442d59adbb9affc8b7f51773)
