<p>We are integrating Eclipse Ditto into a digital twin platform, but we have encountered a problem while testing and we don't really know how to fix it.</p>
<p>We made a question related to this one time ago and it worked.
Here you have the link to that question: <a href="https://stackoverflow.com/questions/76044974/eclipse-ditto-does-not-send-all-things-events-over-target-connection">Eclipse Ditto does not send all things events over target connection</a></p>
<p>Unfortunately it started failling again but we dont think that the problem is the same as before.</p>
<p>We are in the same scenario, the goal is to receive in 593 twins (Ditto Thing) the result of a simulation. The idea is to be able to do several simulation runs simultaneously and that each simulation run sends 593 messages to a Kafka topic. For example, for 6 runs we will have 3558 messages in the topic.</p>
<p>We upgraded all fields and values that were given to us deleted javascript mapping and tested with the maximun amount of simulations, 360. It worked with 360 simulations that send a total of 213480 messages. No messages were droped in any of the tests that we carried out. Perfect!.</p>
<p>So we decided to make some test over all the platform to measure latency.
The workflow of the data is the following:</p>
<p><strong>Simulation --&gt; Kafka --&gt; Ditto --&gt; MQTT (Mosquitto) --&gt; Database</strong></p>
<p>We made a script that sended 1 simulation, waited the data to be stored into the database and then retrieved timestamps.
When al 593 messages arrived, the script sended 2 simulations, waited the all 1186 messages to arrive to the db and then sended a run with 3 simulations.
The script should stop when it reached 360 simulations simulataneously.</p>
<p>We found that ditto was not capable of processing data from 200 simulations even when it was previously capable of supporting 360.
We tried giving Ditto and its components more resources, don't worry we are still free resources, but nothing changed. It even got worse.</p>
<p>We decided to reinstall every component with the configuration that worked previously but now we found some problems:</p>
<ul>
<li>Sometimes some messages remains in Kafka and Ditto don't read them.</li>
<li>Sometimes all data is read from Kafka but no messages are sent to MQTT.</li>
<li>Sometimes it read some messages from Kafka but not all and then, Ditto sends the read data to MQTT multiple times.</li>
</ul>
<p>The funny thing is that <strong>all those unread/unsended messages sometimes are sent after 1 or 2 hours to the MQTT broker</strong>, even though we delete all messages from the Kafka topic. We though that Ditto stores some data in a cache, but we dont know how to clear it or stop it.</p>
<p>Furthermore, despite all these problems, we have 5 twins receiving data every 15 minutes and sending it over MQTT via other connections. These twins are working properly at all times.</p>
<p>On the other hand we are a little bit confused about resources management cause we are using Kubernetes. We dont know exactly the amount of resources that Ditto need for a specific amount of connections, things, etc, or even if we need to give arguments to the JVM. Sometimes connections pods are restarted due to an <em>AskTimeoutException</em> error.</p>
<p>Here are the connections we have established, their logs and metrics, along with the Helm's values.yaml.</p>
<ul>
<li><p>Before executions:</p>
<ul>
<li>Source connection status : <a href="https://pastebin.com/xgtqFZab" rel="nofollow noreferrer">https://pastebin.com/xgtqFZab</a></li>
<li>Target connection status : <a href="https://pastebin.com/YMJE3xs2" rel="nofollow noreferrer">https://pastebin.com/YMJE3xs2</a></li>
</ul>
</li>
<li><p>After executing 1 simulation (593 messages):</p>
<ul>
<li><p>Source connection status : <a href="https://pastebin.com/jaxB7LQ0" rel="nofollow noreferrer">https://pastebin.com/jaxB7LQ0</a></p>
</li>
<li><p>Target connection status : <a href="https://pastebin.com/RZ4p0Mq9" rel="nofollow noreferrer">https://pastebin.com/RZ4p0Mq9</a></p>
</li>
<li><p>Source connection metrics : <a href="https://pastebin.com/mGKPDr8V" rel="nofollow noreferrer">https://pastebin.com/mGKPDr8V</a></p>
</li>
<li><p>Target connection metrics : <a href="https://pastebin.com/kwTZHmiK" rel="nofollow noreferrer">https://pastebin.com/kwTZHmiK</a></p>
</li>
<li><p>Source connection logs : <a href="https://pastebin.com/dfaDyUS5" rel="nofollow noreferrer">https://pastebin.com/dfaDyUS5</a></p>
</li>
<li><p>Target connection logs : <a href="https://pastebin.com/TxRVHfjq" rel="nofollow noreferrer">https://pastebin.com/TxRVHfjq</a></p>
</li>
</ul>
</li>
</ul>
<p>When executing just one simulation at the begining of the morning it works correctly, but when executing simulations after that, it start failing.</p>
<ul>
<li>After executing 11 simulations (6.523 messages)
<ul>
<li>Source connection status : <a href="https://pastebin.com/G9mYpmnT" rel="nofollow noreferrer">https://pastebin.com/G9mYpmnT</a></li>
<li>Target connection status : <a href="https://pastebin.com/0ij6pDYn" rel="nofollow noreferrer">https://pastebin.com/0ij6pDYn</a></li>
<li>Source connection metrics : <a href="https://pastebin.com/QjTDwBmL" rel="nofollow noreferrer">https://pastebin.com/QjTDwBmL</a></li>
<li>Target connection metrics : <a href="https://pastebin.com/P5MVFTJu" rel="nofollow noreferrer">https://pastebin.com/P5MVFTJu</a></li>
<li>Source connection logs : <a href="https://pastebin.com/Kpft7Tme" rel="nofollow noreferrer">https://pastebin.com/Kpft7Tme</a></li>
<li>Target connection logs : <a href="https://pastebin.com/wMe4DYnA" rel="nofollow noreferrer">https://pastebin.com/wMe4DYnA</a></li>
</ul>
</li>
</ul>
<p><strong>Source</strong> connection:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;connection-for-pivot-simulation-with-idSimulationRun&quot;,
    &quot;connectionType&quot;: &quot;kafka&quot;,
    &quot;connectionStatus&quot;: &quot;open&quot;,
    &quot;uri&quot;: &quot;tcp://KAFKAIP&quot;,
    &quot;sources&quot;: [
        {
            &quot;addresses&quot;: [
                &quot;riego&quot;
            ],
            &quot;consumerCount&quot;: 1,
            &quot;qos&quot;: 1,
            &quot;authorizationContext&quot;: [
                &quot;nginx:ditto&quot;
            ],
            &quot;headerMapping&quot;: {
                &quot;correlation-id&quot;: &quot;{{header:correlation-id}}&quot;,
                &quot;namespace&quot;: &quot;{{ entity:namespace }}&quot;,
                &quot;content-type&quot;: &quot;{{header:content-type}}&quot;,
                &quot;connection&quot;: &quot;{{ connection:id }}&quot;,
                &quot;id&quot;: &quot;{{ entity:id }}&quot;,
                &quot;reply-to&quot;: &quot;{{header:reply-to}}&quot;
            },
            &quot;replyTarget&quot;: {
                &quot;address&quot;: &quot;{{header:reply-to}}&quot;,
                &quot;headerMapping&quot;: {
                    &quot;content-type&quot;: &quot;{{header:content-type}}&quot;,
                    &quot;correlation-id&quot;: &quot;{{header:correlation-id}}&quot;
                },
                &quot;expectedResponseTypes&quot;: [
                    &quot;response&quot;,
                    &quot;error&quot;
                ],
                &quot;enabled&quot;: true
            }
        }
    ],
    &quot;targets&quot;: [],
    &quot;clientCount&quot;: 5,
    &quot;failoverEnabled&quot;: true,
    &quot;validateCertificates&quot;: true,
    &quot;processorPoolSize&quot;: 1,
    &quot;specificConfig&quot;: {
        &quot;saslMechanism&quot;: &quot;plain&quot;,
        &quot;bootstrapServers&quot;: &quot;KAFKAIP&quot;
    },
    &quot;tags&quot;: []
}
</code></pre>
<p><strong>Target</strong> connection:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;mqtt-connection-for-telegraf-pivot&quot;,
    &quot;connectionType&quot;: &quot;mqtt-5&quot;,
    &quot;connectionStatus&quot;: &quot;open&quot;,
    &quot;uri&quot;: &quot;tcp://MQTTIP&quot;,
    &quot;sources&quot;: [],
    &quot;targets&quot;: [
        {
            &quot;address&quot;: &quot;opentwins/{{ topic:channel }}/{{ topic:criterion }}/{{ thing:namespace }}/{{ thing:name }}&quot;,
            &quot;topics&quot;: [
                &quot;_/_/things/twin/events?namespaces=pivot&amp;extraFields=thingId,attributes/_parents,features/idSimulationRun/properties/value&quot;,
                &quot;_/_/things/live/messages&quot;,
                &quot;_/_/things/live/commands&quot;
            ],
            &quot;qos&quot;: 1,
            &quot;authorizationContext&quot;: [
                &quot;nginx:ditto&quot;
            ],
            &quot;headerMapping&quot;: {}
        }
    ],
    &quot;clientCount&quot;: 5,
    &quot;failoverEnabled&quot;: true,
    &quot;validateCertificates&quot;: true,
    &quot;processorPoolSize&quot;: 1,
    &quot;tags&quot;: []
}
</code></pre>
<p><strong>Values:</strong></p>
<pre class="lang-yaml prettyprint-override"><code>
swaggerui:
  enabled: false

mongodb:
  enabled: false

global:
  prometheus:
    enabled: true

dbconfig:
  connectivity:
    uri: mongodb://dt-mongodb:27017/connectivity
  things:
    uri: mongodb://dt-mongodb:27017/things
  searchDB:
    uri: mongodb://dt-mongodb:27017/search
  policies:
    uri: mongodb://dt-mongodb:27017/policies

connectivity:
  replicaCount: 5
  extraEnv:
    - name: MQTT_CONSUMER_THROTTLING_ENABLED
      value: &quot;false&quot;
    - name: MQTT_CONSUMER_THROTTLING_LIMIT
      value: &quot;100000&quot;
    - name: KAFKA_CONSUMER_THROTTLING_ENABLED
      value: &quot;false&quot;
    - name: KAFKA_CONSUMER_THROTTLING_LIMIT
      value: &quot;100000&quot;
    - name: KAFKA_SESSION_TIMEOUT_MS
      value: &quot;60000&quot;
    - name: CONNECTIVITY_MQTT_MAX_QUEUE_SIZE
      value: &quot;100000&quot;
    - name: CONNECTIVITY_KAFKA_MAX_QUEUE_SIZE       
      value: &quot;100000&quot;
    - name: CONNECTIVITY_SIGNAL_ENRICHMENT_BUFFER_SIZE
      value: &quot;300000&quot;
    - name: CONNECTIVITY_MESSAGE_MAPPING_MAX_POOL_SIZE
      value: &quot;10&quot;
  resources:
    requests:
      cpu: 2000m
    limits:
      memory: 3Gi

gateway:
  resources:
    requests:
      cpu: 1000m
    limits:
      memory: 768Mi

nginx:
  replicaCount: 2
  service:
    type: NodePort
    nodePort: 30525
  resources:
    requests:
      cpu: 500m
    limits:
      cpu: 1000m
      memory: 768Mi

policies:
  resources:
    requests:
      cpu: 1000m
    limits:
      memory: 768Mi

things:
  replicaCount: 1
  resources:
    requests:
      cpu: 1000m
    limits:
      memory: 8192Mi

thingsSearch:
  resources:
    requests:
      cpu: 1000m
    limits:
      memory: 768Mi

</code></pre>

Julia Robles
<p>The behaviour described on OP was a product of multiple errors on Ditto 3.1.2</p>
<ul>
<li>AskTimeoutError: Caused by some badly designed NetworkPolicies. For more information, see <a href="https://github.com/eclipse-ditto/ditto/issues/1649" rel="nofollow noreferrer">this issue</a></li>
<li>Kafka redelivers: Caused by connectivity sending messages again and again on error. See this <a href="https://github.com/eclipse-ditto/ditto/pull/1657" rel="nofollow noreferrer">PR</a></li>
<li>High memory usage: Due to Akka's nature, disabling throttling is a terrible idea. Connectivity will continue to feed the system with messages that will eventually bring down the system. Throttling isn't ideal either, but is better than having a cluster crash.</li>
</ul>
<p>We believe version 3.3.0 has solved most of our issues, but further testing is needed.</p>
