Concurrent API endpoint calls

Hey there! I’m confused about how PSU handles concurrent calls to a single endpoint. Are they paralellized? It doesn’t seem so. :frowning:

I defined a testing endpoint /wait/:seconds with a simple Start-Sleep -seconds $seconds, run in PS 5.1 environment, non-persistent runspace.

When I call /wait/10 and immediately after that /wait/1, the first call waits 10 secs and the other just one sec. Nice, expected.
But when I call three /wait/10s they keep waiting for their predecessor to complete, so the last one completes in 30 secs. That puzzled me… Are they treated as different endpoints, although the last part of URI is a parameter?

Thanks for claryfing what’s going on under the hood.

My goal is to be able to handle a few dozen concurrent calls to one endpoint (on a single node).

Lukas

Product: PowerShell Universal
Version: 3.8.11
Hosted as a Windows Server 2022 service, single node

Every call to an endpoint is run in a different runspace within a runspace pool. Maybe I’m not understanding your test but when I open 2 PowerShell processes and then run the same 10 second wait, you can see each call waits exactly ten seconds and are running at the same time.

PS C:\Users\adamr> Get-Date; Invoke-RestMethod http://localhost:5000/wait/10 -Method GET; Get-Date

Friday, September 29, 2023 9:33:46 AM
Friday, September 29, 2023 9:33:56 AM
PS C:\Users\adamr> Get-Date; Invoke-RestMethod http://localhost:5000/wait/10 -Method GET; Get-Date

Friday, September 29, 2023 9:33:48 AM
Friday, September 29, 2023 9:33:58 AM

Hi Adam, thanks for your reply and testing.
It seems I can only reproduce the behaviour when the GET endpoints are called from tabs in Chrome browser. When the tabs don’t have focus they’re for some reason waiting for the others.
I think we can mark this as solved :slight_smile:
Lukas

1 Like