OpenAPITools / OpenAPITools/openapi-generator
slow response time with generated csharp (c# .net)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Sending my simple get request with Postman takes max 430ms on the first request, and 40-30ms for repeated.
But using the generated c# classes, it takes 40000-50000ms in both async and non-async operations for the same request.
repeated takes 71-74ms, which is faster but double than Postman. after repeating the same request 5 times, I sent a different request that took 120+ms and 90+ms on repeat.
Trying the same thing with NSwag, I get the same initial delay, but repeated request takes 22-25ms.
- 40+ seconds is way too long for an initial request. (max 500ms expected)
- 70+ms for repeated requests is longer than expected for repeated requests. (max 50ms expected)
openapi-generator version
7.0.1
OpenAPI declaration file content or url
note that the yaml was simplified and unused components and paths were removed.
openapi: "3.0.3"
info:
title: Client API
version: "2.0"
security:
- ProjectId: []
components:
securitySchemes:
ProjectId:
description: >
The ID of the project.
type: apiKey
in: header
name: project-id
schemas:
error:
type: object
properties:
message:
type: string
uuid:
type: string
format: uuid
project:
type: object
required: [id]
properties:
id:
$ref: "#/components/schemas/uuid"
responses:
badRequest:
description: Invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/error"
unauthenticated:
description: Authentication failure
content:
application/json:
schema:
$ref: "#/components/schemas/error"
serverError:
description: Internal server error
content:
application/json:
schema:
$ref: "#/components/schemas/error"
paths:
/project:
get:
operationId: getProject
summary: Get public project info
responses:
200:
description: The project object.
content:
application/json:
schema:
$ref: "#/components/schemas/project"
"4XX":
$ref: "#/components/responses/badRequest"
500:
$ref: "#/components/responses/serverError"
Generation Details
This is the code gen command:
java -jar openapi-generator-cli-7.0.1.jar generate -i openapi.yaml -g csharp -o ./GeneratedClient --additional-properties targetFramework=net47,library=restsharp
Steps to reproduce
- Create and run a server that accepts your guid header.
- Generate using the info in the Generation Details
- run C# code:
var client = new Org.OpenAPITools.Api.DefaultApi("https://client.api.myserver.com/");
client.Configuration.DefaultHeaders.Add("project-id", "00000000-0000-0000-0000-000000000000");
Console.WriteLine(client.GetProject().ToString());
Note that I have replaced address and guid with generic values. The timing logs are also removed to make it easier to read.
Related issues/PRs
https://stackoverflow.com/questions/72814123/openapi-generator-c-net6-extremely-slow-http-requests-under-certain-condi
https://stackoverflow.com/questions/754333/why-is-this-webrequest-code-slow
Suggest a fix
I believe that the issue of the initial reqest is that the request is configuring or auto-detecting proxies. This issue is also in NSwag.
request.Proxy = null;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the generated C# client from the supplied OpenAPI YAML using the 7.0.1 command with library=restsharp, then compare its first and repeated request timings with Postman and NSwag. Inspect the generated client's request and proxy configuration, including the suggested request.Proxy setting. Done means the initial request is near the reported 500ms expectation and repeated requests are near 50ms without breaking normal requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100