ModbusTCPNetwork Driver Threading

We have a rather large site with total 50,000+ modbus points coming from 200+ modbus IP devices. All of it is coming into 1 modbus TCP network on the supervisor. Supervisor is running on an expensive Windows Server VM.

We’re seeing 95%+ busy time…

If we split the devices into multiple modbus TCP networks in the config tree would that help with the busy time? Will this basically create new threads for the modbus “stack” if you will?

Do we need to change the TCP port to accomplish multi threading or just simply adding a new ModbusTCPNetwork to the tree?

I would believe that yes, it would help break down the busy time.
But separating and making sure your tuning policy are correctly set also helps a lot.

You can also optimize through the device poll config that bundles up points that are sequential and request one reading for all at the same time.

after we split the devices across multiple networks we did indeed confirm the busy time went down and things are working better now. we combined that with using prime numbers as poll intervals as well. poll configs we luckily setup correctly in the beginning.

The prime number poll intervals trick is gold — avoids those nasty harmonic spikes when everything tries to poll on the exact same second. Just curious, did you keep the default ThreadPoolWorker settings on the Supervisor host, or did you have to bump the thread pool count in the system configuration after splitting into multiple Modbus networks? With 50k points across 200 devices, standard tuning policies often queue up if the worker pool hits its cap during network hiccups. Glad to hear the busy time dropped though!

thanks we didn’t touch the threadpoolworker since we are still unsure how it exactly works. im sure that with the specs on our VM we can but i wish tridium would publish an official doc on threads and JVM settings to maximize the available server resources…

Your first question has a clean answer in the code: yes. The poll scheduler is a property of the network, and BPollScheduler.startThread creates exactly one plain java.lang.Thread per scheduler, named Poll: followed by the network name. Every ModbusTcpNetwork you add gets its own scheduler and so its own poll thread. The TCP port is irrelevant, because each ModbusTcpDevice carries its own ipAddress, port and socketStatus and opens its own socket. Splitting the tree is the whole mechanism.

Be precise about what busyTime told you. BPollScheduler.poll brackets only doPoll with Clock.ticks and accumulates it into totalPollTime, and updateStats prints totalPollTime over scheduler uptime. That is the duty cycle of one thread, not host CPU. At 95 percent the poll thread is nearly always inside a transaction, and more vCPUs cannot help, because nothing else runs that loop.

It sits inside transactions because the poll thread does the wire I/O itself. BModbusClientPollGroup.poll calls device.readRegisters or readStatusRegisters straight through, blocking, on that thread, so busyTime is mostly socket wait. Timeouts dominate it: BBasicNetwork defaults responseTimeout to 500ms with retryCount 1, and the poll group swallows the exception and logs poll device timeout at info level, so one sulking device quietly eats every other device’s budget on that network.

The ThreadPoolWorker lever is not connected to Modbus reads. A network’s dispatcher, worker and writeWorker are BBasicWorker and BBasicCoalescingWorker, which extend BWorker, and Worker.start builds a single thread, named BscWkr or BscClscWkr plus the network and slot name. BThreadPoolWorker, the one whose maxThreads defaults to 4, is abstract, and no Modbus jar in 4.15.5 references it at all. Its subclasses sit in rdb, obix, opc, batchJob, the niagara driver, orion audit and vykonPro, so raising it moves that work and never a Modbus read.

Check one thing before tuning rates. pollQueue polls at most one entry per bucket per pass, then sets the next deadline from rate minus size times the last poll duration, divided by size. So fastRate, normalRate and slowRate are targets for a whole bucket cycle, not per point intervals. Once bucket size times average transaction time exceeds the rate, that sleep stops being positive and the loop runs flat out, which is where you were. It also paces off the previous transaction rather than a wall clock grid, so prime intervals buy less here than folklore suggests.

Then check what is in the buckets. BModbusClientProxyExt.getPollGroupCode looks for an enabled poll config entry covering the point address and register count. If it finds one, the entry is the bucket member and dataSource is set to devicePoll. If not, the point becomes its own poll group and dataSource becomes pointPoll, a Modbus transaction of its own. That property is readonly and transient, so it only reads true on a running station, and every pointPoll is a queue slot nobody budgeted for.

Two last details. BBasicPollGroup.getPollFrequency returns the fastest frequency among the subscribed proxies in the group, so one point left on Fast promotes a whole register block. And the base BTuningPolicy carries only minWriteTime, maxWriteTime, writeOnStart, writeOnUp, writeOnEnabled and staleTime, none of which touch read rate, so tuning policies were never the read side fix. All of this is read off the 4.15.5 framework source, not measured on a station.

theres a key part here worth noting. If any single point is set to fast and the rest of the point group is slow the whole group is treated as fast? so if this is consecutive registers 40001-40050 and 40025 is set to fast all 50 points in this group are requested with the fast timer? what i’m concluding here is that consecutive registers all need to have the same poll frequency? if i want register 40025 to be faster but the rest of the registers to be slower do i need to separate 40025 from the poll config entry?

Yes, and it is worth being precise about what “group” means there, because it is the poll config entry, not the register span as such.

Poll groups are keyed by the entry. BModbusClientProxyExt.getPollGroupCode takes your point’s absolute address and runs BDevicePollConfigTable.findPollConfigEntry against the device’s active entries for that register type, and every point that resolves to the same BDevicePollConfigEntry shares one BModbusClientPollGroup. A point that matches no entry becomes its own group and polls on its own, which is the pointPoll data source you see on the proxy ext.

The rate is then picked in BBasicPollGroup.getPollFrequency, and the loop is literally: start at slow, walk the subscribed proxies, keep the fastest one seen. BPollFrequency is fast 0, normal 1, slow 2, so fastest wins. One fast point in the entry and all fifty registers ride the fast bucket. So yes, to get 40025 on its own timer you split the poll config into three entries: 40001 to 40024, 40025 alone, 40026 to 40050.

Two things to weigh before you do it.

Only subscribed proxies count. A point with no history, no link and nobody looking at it is not in the subscribed list, so it does not drag the group’s rate while it sits idle.

And you would be trading register count for round trips, which is the wrong currency on your site. readRegisters issues one request for up to 125 registers, so that block costs you one transaction per cycle today. Split, it is one small fast transaction plus two slow ones. Clearly worth it at 1s against 30s, close to pointless if your fast and slow rates sit near each other.

One more that bears directly on the busy time you started with: the bucket rate is a cycle target, not a per group interval. pollQueue polls one group per pass, then sleeps (rate - size x lastPollTime) / size, so every group you add to fast divides the same second among more members. Once the sum of poll times exceeds fastRate that sleep goes negative and the bucket free runs.

thank you! i also want to confirm that if we are using the default tuning policy out of the palette and every point is set to “normal rate” then normal rate is the only one used correct?

I think the two halves of that sentence come apart a little, and it is worth
separating them before you tune anything.

The tuning policy has no rate in it. A TuningPolicy carries exactly six
properties: minWriteTime, maxWriteTime, writeOnStart, writeOnUp, writeOnEnabled
and staleTime. All of them are write-side or staleness; none of them says how
often a point is read. So the default policy out of the palette is not what sets
your poll rate, and editing it will not move your busy time.

The rate lives in two other places. pollFrequency on each proxy ext picks a
bucket - fast, normal, slow, ordinals 0, 1, 2 - and the three rate values on the
network’s Poll Scheduler say what each bucket’s cycle target is. Out of the
palette those are fast 1s, normal 5s, slow 30s.

So yes: with every proxy ext left at normal, the normal bucket is the only one
with members in it. Three things are still worth knowing before you read the
statistics as “only normal is running”.

  1. All three buckets run every pass regardless. pollQueues() calls fast, then
    normal, then slow, unconditionally. An empty bucket polls nothing, sleeps a flat
    one second, and still increments its own cycle counter. So Fast Cycle Time and
    Slow Cycle Time keep moving on the scheduler view with nothing in either bucket.
    That on its own is not evidence that something is being polled there.

  2. Not all traffic goes through the buckets at all. subscribe() pushes the
    pollable onto a dibs stack as well as into its bucket, and pollDibs() drains
    dibs completely at the top of every pass, before any bucket is touched. That is
    the immediate first read you get when something subscribes. On a site your size,
    with operators opening graphics and histories starting and stopping, that is not
    a rounding error, and no rate governs it. It has its own counters - Dibs Polls
    and Dibs Count - and they are the ones to read next to Normal Polls before
    concluding the normal rate is the whole picture.

That also bears on the number you started this thread with. Both paths call the
same poll() method, and that method is where totalPollTime is accumulated, so
busy time is dibs plus all three buckets, not the bucket traffic alone. A busy
time that will not come down while the normal rate goes up is the signature of
dibs traffic rather than of a rate that is too fast.

  1. In the Modbus driver the thing in the bucket is the poll group, not the
    point, keyed by the poll config entry as in the earlier post. The group’s
    getPollFrequency starts at slow and keeps the fastest subscribed proxy it sees.
    With everything at normal, every group reports normal. Set one point in an entry
    to fast and the whole group changes bucket, and it changes back only when that
    point is unsubscribed or set back.

One useful side effect of how this is built: the scheduler rebuilds all three
buckets from scratch every ten seconds, so a rate change takes effect within ten
seconds, with no restart and no re-subscribe.

Not all traffic goes through the buckets at all. subscribe() pushes the
pollable onto a dibs stack as well as into its bucket, and pollDibs() drains
dibs completely at the top of every pass, before any bucket is touched. That is
the immediate first read you get when something subscribes. On a site your size,
with operators opening graphics and histories starting and stopping, that is not
a rounding error, and no rate governs it. It has its own counters - Dibs Polls
and Dibs Count - and they are the ones to read next to Normal Polls before
concluding the normal rate is the whole picture.

That also bears on the number you started this thread with. Both paths call the
same poll() method, and that method is where totalPollTime is accumulated, so
busy time is dibs plus all three buckets, not the bucket traffic alone. A busy
time that will not come down while the normal rate goes up is the signature of
dibs traffic rather than of a rate that is too fast.

If I’m understanding you correctly, Dibs is essentially an immediate/first-read mechanism that occurs when something subscribes to a point. That initial poll happens outside of the Fast/Normal/Slow scheduling, and after that the point continues to be handled by its normal poll group for ongoing polling.

Is there any way to disable or prevent Dibs polling?

At our Supervisor, we have numeric interval histories on many of the points, and we also query points through the JSON Toolkit to publish values via MQTT. We also have operators viewing Px graphics as well as HTML summaries that are also loading ord path values.

Ideally, I would want the Modbus points to be polled strictly according to their configured Normal rate, regardless of whether a history, MQTT query, or graphic requests/subscribes to the point.

For example, if a point is configured for Normal = 5 seconds, I would prefer:

Modbus → poll every 5 seconds → history/MQTT/graphics use the most recently polled value

rather than:

history/MQTT/graphic subscription → Dibs → additional immediate Modbus poll

Is that behavior configurable, or is Dibs an inherent part of how Niagara handles subscriptions that can’t be disabled?

And specifically, if I configure a numeric history to collect every 5 seconds, does the history simply record the most recently available point value, or can the history subscription itself cause an immediate Modbus poll through Dibs?

Short answer to the first question: no, there is no switch. BPollScheduler.subscribe(BIPollable) does dibs.push(p) and then adds the pollable to fast, norm or slow by its poll-frequency ordinal. The push is unconditional — there is no property, facet or tuning setting beside it. The only related switch is pollEnabled on the scheduler, and that stops every bucket as well, so it is not the one you want.

But the thing you are picturing — every graphic, MQTT query and history collection causing another immediate Modbus read — is not what happens, and the reason is one line up the stack.

Dibs is not per subscriber. It is per zero-to-one transition of a poll group. BBasicPollGroup.readSubscribed(proxy) adds the proxy to mySubscribedProxies, then:

if (!this.subscribed) { scheduler.subscribe(this); this.subscribed = true; }

The second, third and fiftieth subscriber on a group that is already subscribed add nothing to the dibs stack. readUnsubscribed only calls scheduler.unsubscribe when mySubscribedProxies.size() == 0. So a dibs poll costs you one read per group each time that group goes from nobody to somebody — not one read per Px page opened.

Which leads to your history question, and I think the answer is the opposite of what you are bracing for.

An enabled history extension makes its point permanently subscribed. BHistoryExt.requiresPointSubscription() returns getEnabled(). BControlPoint.checkExtensionsRequireSubscription() walks the point’s extensions and calls setPermanentlySubscribed(…), which sets a bit in the component’s slot map; BComponent.isSubscribed() returns true whenever that bit is set. So on every Modbus point carrying an enabled history, the poll group subscribes once, at start, and never unsubscribes while the station runs. Exactly one dibs poll, ever, and strictly the Normal bucket rate after that. That is the behaviour you described wanting, and on your history points you already have it.

The collection itself never reads the device. BIntervalHistoryExt runs off a Clock.Ticket; activated() calls writeRecord(currentTime, value) with the point’s own status value and then scheduleCollection(). It samples the point’s current out. It cannot cause a Modbus read, at five seconds or at any other interval.

So the dibs traffic you are carrying is not coming from the history points. It is the points with no enabled history extension — the ones only a Px page, a JSON Toolkit read or an MQTT publish ever touches. Those genuinely do go subscribe, dibs, unsubscribe, and round again the next time somebody opens the graphic.

Two practical consequences.

If you want a particular point polled strictly on its Normal rate with no on-demand reads, put an enabled history extension on it. A totalizer does the same job — BNumericTotalizerExt.requiresPointSubscription() also returns true — and so does a link: isSubscribed() is also true while knobCount > 0 and the point is running, so anything wired into control logic is already subscribed for as long as it runs. There is no “no dibs” checkbox to go looking for; those are the levers.

And the cost side, which bears on the number you opened the thread with. Permanently subscribed means polled forever, whether anybody is looking or not. With histories on many of 50k points, the Normal bucket carries that load 24 hours a day. Before you conclude dibs is the problem, read Dibs Polls against Normal Polls on the scheduler view. If Normal dwarfs dibs, your busy time is the permanent subscriptions doing exactly what they were asked to do, and the lever is the rate and the point count, not the subscription mechanism.

(Read off the 4.15.5 jars: driver-rt javax.baja.driver.util.BPollScheduler, basicDriver-rt com.tridium.basicdriver.util.BBasicPollGroup and BBasicProxyExt, control-rt javax.baja.control.BControlPoint and BPointExtension, history-rt javax.baja.history.ext.BHistoryExt and BIntervalHistoryExt.)