The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content

Performance and load

2612

An application runs on a server that a whole organization shares. A form extension loads every time anyone opens a work item of the configured type, a sidebar every time someone opens a table, and each load sends its requests again. Server scripts run in the same Java process as Polarion and read from the same repository, index and database. A slow or chatty application therefore costs more than its own users' time: it slows down Polarion for everybody on the server.

This page collects what keeps an application light. Most of it is ordinary web practice. The Polarion-specific parts are the Lucene and SQL queries and the server scripts.

Rules of thumb

The numbers below are not limits that Polarion enforces. They are reasonable targets for a view that opens automatically with a page. Go beyond them when the use case needs it and you have measured the result.

Target
REST requests when a view opens1 to 3; never one request per item
Items loaded by a viewwhat it shows, usually up to 100; offer Load more or a search beyond that
Response sizeunder about 100 KB for a view that opens automatically
Debounce on selection changes and typing150 to 300 ms
Pollingnone by default; if unavoidable, 60 s or more and only while the view is visible
Server script run timeunder 1 s for a view that opens automatically, a few seconds for an action the user started
Retriesat most one, after a delay, and only for temporary errors

Load only what the view shows

Name the fields. Ask with fields[workitems] for the fields the view shows. Rich-text fields such as description can be large; leave them out unless the view renders them.

// Don't: every field of up to 100 work items, then filtered in the browser.
const all = await restFetch(context, `/projects/${p}/workitems?page[size]=100`);
const open = all.data.filter((w) => w.attributes.status === "open");

// Do: let the server filter, and ask only for the columns the table shows.
const params = new URLSearchParams({
  query: "status:open AND type:task",
  "fields[workitems]": "id,title,status",
  "page[size]": "50",
});
const open = await restFetch(context, `/projects/${p}/workitems?${params}`);

Filter on the server. A Lucene query runs against the index. Filtering in the browser means the server has already read, serialized and sent every item you throw away.

One request for related items. include returns the work item and its linked items in one response. A loop that requests each linked item separately sends N + 1 requests for the same data.

Batch by id. A selection of 40 work items is one request with query=id:(DP-1 DP-2 …), not 40. Split very long id lists into chunks of 100, as the selection sidebar and the release checklist do.

Page, but stop. Walk pages only as far as the user needs. A view that silently reads every page of a 20,000-item project reads 200 pages of 100 items each time it opens.

Search instead of listing. For a user or plan picker, send what the user typed as a query and show the first matches. Loading every user of a large installation into a select list is slow for the server and unusable for the user.

Send fewer requests

  • Load once, refresh on request. Load when the view opens and when the user presses Refresh. Data that changes rarely (field metadata, enumeration options, status names) can be loaded once per page.
  • Debounce. Keyboard navigation in a table fires a selection event per row. Wait until the selection has been stable for 150 to 300 ms before you load, as described in React to selection changes.
  • Drop stale requests. When a newer request replaces an older one, ignore the older response or abort it with an AbortController. Otherwise a slow old response can overwrite a newer result, and the user tends to click again.
  • Don't poll by default. A sidebar that reloads every 10 s on 200 open browsers sends 1,200 requests a minute and changes nothing for most users. If the view must follow changes, poll rarely, and stop while the page is hidden:
useEffect(() => {
  const tick = () => {
    if (document.visibilityState === "visible") void load();
  };
  const timer = setInterval(tick, 60_000);
  return () => clearInterval(timer);
}, [load]);
  • Cache in the page. Keep results in a module-level map or in state, keyed by their parameters. GET requests to your own endpoints can be cached by the browser if the URL stays the same; see Caching expensive results.

Errors and retries

A retry loop turns one failed request into many at the moment the server is already struggling.

  • Do not retry 400, 401, 403 or 404. The next attempt fails the same way.
  • For 429, 502, 503 and 504, retry at most once, after a delay of one or two seconds. If the response carries a Retry-After header, wait at least that long.
  • Show the error and let the user try again. A Retry button costs nothing when nobody presses it.
// Don't: retries forever, immediately, for every kind of error.
while (true) {
  try { return await restFetch(context, url); } catch { /* try again */ }
}

Server scripts

An endpoint script runs inside Polarion with the caller's permissions, and the caller waits until it finishes. See Endpoint runtime.

  • Bound every loop. Cap the number of items, the depth of a link walk and the number of pages. Return the cap in the response, so the view can say "Showing the first 500".
  • Query, don't walk. Find work items with a Lucene query through the tracker service. Iterating over all work items of a project to find a few is a full scan of the project.
  • Return what the view needs. Map objects to small JSON with the fields the view renders. Do not return whole objects or long rich-text values the view never shows.
  • Save once. Set all fields of an object, then call save() once. Each save() is a separate change in the repository.
  • Keep writes on POST and small. A bulk change of hundreds of items belongs in a job or a scheduled script, not in a request a user waits for.

SQL

Polarion keeps a PostgreSQL database next to its index, and SQL can be faster than Lucene for counting and joining across work items, documents, links and test runs. The same power makes a careless query expensive: it runs on the database every Polarion user depends on.

  • Filter by project first, and by type or other indexed columns.
  • Select only the columns you need. Inside Polarion, a query that returns objects selects c_uri.
  • Join Polarion tables on c_uri. When you combine SQL with a Lucene query through LUCENE_QUERY(...), join its result on c_pk, as the SDK examples show.
  • Use EXISTS instead of joining a large table only to check that a row exists.
  • Add LIMIT when the view shows a fixed number of rows.
  • Avoid leading wildcards (LIKE '%text%') on large text columns such as c_description; they read every row. Use the Lucene full-text search for text.
  • Run the query with EXPLAIN ANALYZE on a copy of production data before it goes into an application.
-- Don't: every column of every work item in every project, joined to all links,
-- filtered by a leading wildcard on the description.
SELECT *
FROM workitem w
LEFT JOIN struct_workitem_linkedworkitems l ON l.fk_uri_p_workitem = w.c_uri
WHERE w.c_description LIKE '%brake%'

-- Do: one project, one type, one link role, EXISTS instead of a join,
-- and only the column Polarion needs to return the objects.
SELECT w.c_uri
FROM workitem w
INNER JOIN project p ON p.c_uri = w.fk_uri_project
  AND p.c_id = 'drivepilot'
WHERE w.c_type = 'requirement'
  AND EXISTS (
    SELECT 1
    FROM struct_workitem_linkedworkitems link
    WHERE link.fk_uri_workitem = w.c_uri
      AND link.c_role = 'verifies'
  )
LIMIT 200

The schema, the join rules and more examples are in the SDK documentation of every installation, at https://<polarion>/polarion/sdk/doc/database/.

Test before production

  • Use a test server with realistic data. A view that is fast on a demo project with 50 work items can be slow on a project with 50,000. Copy a production-sized project to the test server, or generate one.
  • Watch the network tab. Open the view and count the requests, their size and their duration. Then click through a table quickly with the arrow keys and count again.
  • Try more than one user. Open the view in several browsers or for several users at once, especially if it runs a server script.
  • Measure the script. Log the start and end time of an endpoint script on the test server, and try it with the largest input a user can send.
  • Roll out step by step. Configure the view for one project or one work item type first, and watch the server before you add it everywhere.

Checklist

  • Every REST request names its fields with fields[…].
  • Filtering happens in the Lucene query, not in the browser.
  • No request per item: related items through include, selections through id:(…).
  • Lists are capped, with Load more or a search beyond the cap.
  • Selection and typing are debounced; stale responses are ignored.
  • No polling, or a long interval that stops while the page is hidden.
  • No automatic retries for client errors; at most one delayed retry for temporary errors.
  • Server scripts cap items, depth and pages, and return only what the view shows.
  • SQL queries filter by project, select c_uri, and were checked with EXPLAIN ANALYZE.
  • Tested on a test server with production-sized data and more than one user.