MSBA-272 · Lesson 10 of 12 · 19 min

Performance and limits

▶ Video coming soon A video version of this lesson is on the way.

Every spring the registrar's office loads several thousand historical transcript requests from the old records system, and from January the bulk import would run against tables with Wiremu's plug-ins on them. Signe wanted to know, before then, how long the import would take, whether it would be throttled, and whether any plug-in would slow it down enough to matter. That question became a session on performance and the limits Dataverse places on extensions, with a practice run in Wiremu's developer environment using 30,000 anonymized test rows.

Limits that apply to plug-ins

Dataverse protects itself and every other customer on the same infrastructure with limits. For plug-ins, two are fundamental. A message operation must complete within two minutes, including every plug-in registered on it; if it does not, Dataverse throws a timeout and rolls back the operation. And each plug-in should be quick: Microsoft's guidance is that a synchronous plug-in should finish in about two seconds or less, and that anything slower should be registered as asynchronous or redesigned.

A horizontal bar representing the two-minute limit for one message operation. Small segments at the start show the platform's own work and three synchronous plug-ins of under two seconds each. The rest of the bar is empty headroom. Beneath, a second bar shows a badly designed plug-in that calls an external API and waits, filling much of the bar and approaching the limit.
The two-minute limit is shared by everything on the message.

The sandbox also watches each worker process. A plug-in that uses too much memory, runs away in a loop or crashes the process with an unhandled exception in a thread it started is stopped, and other plug-ins running in the same worker can be affected. Microsoft's guidance is not to start background threads or tasks in a plug-in, and where an asynchronous API must be called, to wait for it with GetAwaiter().GetResult() rather than reading .Result, which can hide exceptions and deadlock.

Service protection limits

API calls to Dataverse are subject to service protection limits, which apply per user, evaluated over a sliding window of five minutes. MSBA-270 introduced them; Signe now showed how they shaped the import.

Dataverse service protection limits, as documented by Microsoft.
MeasureLimit per user in a five-minute window
Number of requests6,000
Combined execution time of requests1,200 seconds (20 minutes)
Concurrent requests52

When a client exceeds a limit, Dataverse returns an error, with HTTP status 429 Too Many Requests in the Web API, and a Retry-After value that says how long to wait. A well-behaved client waits that long and tries again. Microsoft's SDK client for .NET and many other libraries do this automatically, but custom integration code must handle it explicitly.

The execution time limit surprised Wiremu. It means the time Dataverse spends on a user's requests counts, not only how many there are, and time spent in plug-ins is part of it. A slow plug-in on a table therefore makes every client that writes to that table hit the limit sooner. With one request at a time, a client cannot use more than five minutes of server time in a five-minute window. With many parallel requests it can, and that is where the twenty minutes of the execution time limit comes into play.

Worked problem

How much parallelism will the import tolerate?

In the practice run, each create of a historical transcript request took about 150 milliseconds of server time, including the fee plug-in. The import tool could run many threads in parallel under one application user. How many threads can run steadily without hitting the execution time limit?

Show solution
  1. In a 300-second window, one thread that is always busy uses at most 300 seconds of server time.
  2. The execution time limit is 1,200 seconds per window, so 1,200 divided by 300 gives 4 threads that are fully busy.
  3. Threads also spend time on the network, so each uses somewhat less than 300 seconds of server time; a few more threads may fit, but not many.
  4. At 150 milliseconds per row and 4 busy threads, 30,000 rows need 30,000 times 0.15, or 4,500 seconds of server time, spread over 4 threads: about 1,125 seconds, roughly 19 minutes.

Answer: About four parallel threads, giving an import of roughly 19 minutes plus network time. More threads would trigger 429 responses rather than finishing faster.

The practice run confirmed the estimate. With eight threads, the import began receiving 429 responses after a few minutes and, because the tool honoured Retry-After, ended up no faster than with four. With four threads it finished in 23 minutes without a single throttling error.

Making plug-ins cheaper

Signe then went through the transcript plug-ins line by line with Wiremu, asking of each operation whether it was needed and whether it could be cheaper. The fee plug-in was already in good shape, but her checklist became part of Lumenvale's review template.

Plug-in performance practices.
PracticeWhy it helps
Use filtering attributes on every Update stepThe plug-in does not run for irrelevant changes
Use images instead of retrieving the primary rowDataverse supplies the data without an extra query
Retrieve only the columns needed; never ask for all columnsLess data read and transferred
Set values on the Target in PreOperation instead of updating in PostOperationOne write instead of two, and no second pipeline run
Move slow work to asynchronous steps or flowsThe user and the transaction do not wait for it
Avoid plug-ins on Retrieve and RetrieveMultipleThey run on every read, including every view
Do not start threads or tasks; call asynchronous APIs with GetAwaiter().GetResult()Avoids crashes and hidden exceptions in the sandbox
Keep external calls short, with timeouts, and out of synchronous steps when possibleAn external service's delay becomes the user's delay

Wiremu found one real gain. The rate reader queried the Transcript Fee Rate table on every execution, asking for all its columns. He changed it to ask for the four columns it used and to filter by delivery method and effective dates in the query rather than in code. The rate table was small, so the saving per call was tiny, but across 30,000 imported rows it took about a minute off the import.

Queries inside plug-ins

Most slow plug-ins Signe had investigated were slow because of their queries, not their logic. The most common pattern was the query inside a loop: a plug-in that received a list of rows and, for each one, retrieved a related row separately. Ten rows meant ten round trips; a thousand rows in a bulk operation meant a thousand. The fix was almost always one query that fetched everything at once, using a condition on a list of IDs or a link to the related table, followed by a lookup in memory.

Other habits mattered too. Queries should ask for the columns they use and no more, filter in the query rather than in code, and set a sensible maximum number of rows when only one or a few are expected. A query that can match many rows must page through them rather than assume they all arrive at once, because Dataverse returns large results in pages. And a plug-in should not query data it already has: the Target, the images and the shared variables from earlier steps in the same operation are free.

Caching

Wiremu suggested caching the rate table in a static variable, since it changed only a few times a year. Signe explained why Lumenvale did not do this. Plug-in instances and their static data can be shared across requests and threads, and they can also be discarded at any time, so a cache must be thread-safe, must expire, and must never be the only source of truth. A cache that kept an old rate after the registrar changed it would charge students the wrong fee until the worker process happened to restart. For a table this small, a narrow query was fast enough and always correct. She allowed caching only for data that never changes during the life of a deployment, such as metadata about a table, and only with a review.

Request entitlements are a different limit

Service protection limits are about protecting the service from bursts. Separately, Microsoft licences include Power Platform request entitlements, which count requests over a day per licensed user or per application user. They are a capacity and licensing matter rather than a protection mechanism, and exceeding them does not produce the same immediate 429 errors. Rupert watched them in the admin centre. For developers, the practical point was the same as before: an integration that makes fewer, larger requests and avoids needless calls is cheaper on every measure.

Bulk messages

For large writes, Dataverse offers messages that do more work per request. ExecuteMultiple wraps up to 1,000 requests of any kind in one call, which reduces network round trips. The newer CreateMultiple, UpdateMultiple and related bulk messages go further for a single table: Dataverse processes the whole batch as one operation, which Microsoft documents as giving higher throughput than sending the same rows individually or in ExecuteMultiple.

Bulk messages have a consequence for plug-ins. A plug-in registered on Create runs for each row when rows arrive through CreateMultiple, because Dataverse keeps existing plug-ins working. But a plug-in can also be registered directly on CreateMultiple or UpdateMultiple and receive all the rows at once, which lets it, for example, read the rate table once for a whole batch. Microsoft recommends registering on the bulk messages for tables where performance matters. Signe added this to the list for January, rather than changing working code weeks before a deadline.

Monitoring

Wiremu asked how they would know in production if a plug-in became slow. Signe was candid that the old plug-in statistics table, which once recorded execution counts and times, is no longer supported, so they would not rely on it. Instead, the team used Dataverse's monitoring through Application Insights, which Rupert had connected for the production environments, to see plug-in execution times and failures, and the plug-in trace log for detail when something looked wrong. They added one alert: a plug-in whose average duration rose above one second over a day sent a message to the developers' Teams channel.

The plan for the spring import

Signe and Wiremu wrote up the findings as a one-page plan for the registrar's spring import, which Maribeth would own. The import would run under a dedicated application user, so its requests had their own service protection limits and did not compete with clerks working in the Transcript Office app. It would use four parallel threads and honour Retry-After on every throttling response. It would run in the evening, outside office hours, so that any slowness affected nobody. It would write rows in batches using CreateMultiple once the plug-ins had been checked against the bulk message, and individually until then. And it would log every failed row to a file with the reason, so a clerk could fix and reload just those rows rather than repeating the whole import.

The plan also listed what would make it go wrong. A new synchronous plug-in added to the transcript request table before the import, such as the AI classification step if someone made it synchronous by mistake, would multiply the import time. A change to the rate table during the import would give rows imported before and after it different fees. So the release checklist for January gained two lines: no new synchronous steps on the transcript request table in the week before the import, and no rate changes on the day it ran.

Rupert read the plan and asked for one addition: a dry run in Registrar Test with the real file, a week before the production run. Signe agreed; it was what she would have asked for herself.

When Dataverse is the wrong place

Some workloads strain Dataverse limits by their nature, and the answer is a different design, not a faster plug-in. MSBA-273 covers these in depth; Signe sketched two because they were already in Lumenvale's plans.

The first was elastic tables, Dataverse tables built on Azure Cosmos DB for very high volumes of simple rows, with optional automatic expiry of each row after a set time. The building management alarm integration planned in MSBA-270 would write a row for every alarm event, potentially thousands a day, into an elastic table lcc_alarmevent with a 30-day expiry. Elastic tables have their own rules about relationships, transactions and queries, so the design kept them for raw events and summarized the important information into standard tables.

The second was Azure Functions. In the same plan, an Azure Function would receive alarm messages from Azure Service Bus and write them to Dataverse, rather than a plug-in or a flow, because a function can absorb bursts, retry independently and run outside Dataverse's two-minute and sandbox limits. A plug-in is a good place to react to a single change in Dataverse. It is a poor place to process a stream of external events. Both pieces remained plans; the alarm integration was not funded.

Common mistakes

  • MistakeAdding threads to a bulk client until it is fast enough.

    InsteadSize parallelism to the execution time limit and honour Retry-After.

  • MistakeWaiting on an external API in a synchronous plug-in without a timeout.

    InsteadMove the call to an asynchronous step or flow, or set a short timeout.

  • MistakeCalling .Result on an asynchronous method in a plug-in.

    InsteadUse GetAwaiter().GetResult(), and do not start background tasks.

  • MistakeRelying on the plug-in statistics table for monitoring.

    InsteadUse Application Insights and the trace log; the statistics table is no longer supported.

  • MistakeProcessing high-volume external events with plug-ins.

    InsteadUse services such as Azure Functions and, where suitable, elastic tables.

Summary and key terms

  • A message operation must finish within two minutes, including its plug-ins; individual plug-ins should take about two seconds or less.
  • Service protection limits per user over five minutes are 6,000 requests, 1,200 seconds of execution time and 52 concurrent requests; clients must honour 429 and Retry-After.
  • Plug-in time counts towards execution time, so slow plug-ins throttle every client that writes to the table.
  • Filtering attributes, images, narrow queries and PreOperation changes keep plug-ins cheap; bulk messages raise throughput.
  • High-volume event processing belongs in services such as Azure Functions and elastic tables.
Service protection limits
Per-user limits on requests, execution time and concurrency in a five-minute window.
Retry-After
The value returned with a throttling error that says how long to wait.
ExecuteMultiple
A message that wraps up to 1,000 requests in one call.
CreateMultiple and UpdateMultiple
Bulk messages that process many rows of one table as a single operation.
Elastic table
A Dataverse table built on Azure Cosmos DB for high volumes, with optional row expiry.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. How long can a message operation, including its plug-ins, run before it times out?

    Show answer

    Two minutes.

  2. What is the combined execution time limit per user in a five-minute window?

    Show answer

    1,200 seconds.

  3. How many requests can ExecuteMultiple contain?

    Show answer

    Up to 1,000.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz