{"id":17851575,"url":"https://github.com/feed0/server-cpu-stress","last_synced_at":"2026-05-06T19:03:30.252Z","repository":{"id":258329416,"uuid":"871405099","full_name":"feed0/server-cpu-stress","owner":"feed0","description":"ASP.NET webapp for processing prime numbers in an EC2 IIS environment","archived":false,"fork":false,"pushed_at":"2024-10-16T18:22:15.000Z","size":1494,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T07:13:19.980Z","etag":null,"topics":["aws-ec2","c-sharp","csharp","dotnet","iis-server","linux","nginx","nginx-proxy","windows-server-2022"],"latest_commit_sha":null,"homepage":"http://18.230.17.178","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feed0.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-11T22:36:29.000Z","updated_at":"2024-10-16T18:22:19.000Z","dependencies_parsed_at":"2024-10-18T13:35:29.160Z","dependency_job_id":"f3536060-e71e-41ef-8642-85befbaa885f","html_url":"https://github.com/feed0/server-cpu-stress","commit_stats":null,"previous_names":["feed0/server-cpu-stress"],"tags_count":0,"template":false,"template_full_name":"github/dotnet-codespaces","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feed0%2Fserver-cpu-stress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feed0%2Fserver-cpu-stress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feed0%2Fserver-cpu-stress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feed0%2Fserver-cpu-stress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feed0","download_url":"https://codeload.github.com/feed0/server-cpu-stress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246850113,"owners_count":20844008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-ec2","c-sharp","csharp","dotnet","iis-server","linux","nginx","nginx-proxy","windows-server-2022"],"created_at":"2024-10-27T23:03:16.633Z","updated_at":"2026-05-06T19:03:25.205Z","avatar_url":"https://github.com/feed0.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Server CPU Stress\r\n\r\nThis ASP.NET repository contains two HTML pages to process prime number up to a given input by an user. \r\nSupports hosting via either 1. Ineternet Information Services 10.0 (IIS) on Windows Server 2022 Base (2024.09.11),\r\nor 2. via Nginx using a reverse proxy nginx.conf file. \r\n\r\n## The webapp\r\n\r\n### Index.cshtml\r\n![image-4](https://github.com/user-attachments/assets/b118b4fd-71a9-4ee4-8865-121289586bb2)\r\n\r\n### Results.cshtml\r\n![image-5](https://github.com/user-attachments/assets/21508fad-34c4-4566-8315-9a997c525b37)\r\n\r\n## Requirements\r\n\r\n### a) Windows Server 2022\r\n- Server Manager Roles: World Wide Web, IIS and Aplication roles;\r\n- .NET 8.0+ SDK in order to publish the webapp;\r\n- .NET 8.0+ Core Host Bundle installed;\r\n- Port inbound rules active on Windows Defender Firewall.\r\n\r\n### b) Linux\r\n- Nginx; \r\n- .NET 8.0+ SDK in order to publish the webapp; \r\n- No hookup: for persistent serving without a need for an open bash use: \r\n```bash\r\nnohup dotnet server-cpu-stress.dll \u0026\r\n```\r\n\r\n## Main files\r\n\r\n### Controller\r\nHomeController.cs holds two function:\r\n\r\n1. IsPrime()\r\n```C#\r\n/// \u003csummary\u003e\r\n/// Check if a number is prime.\r\n/// \u003c/summary\u003e\r\n/// \u003cparam name=\"num\"\u003eThe number to check.\u003c/param\u003e\r\n/// \u003creturns\u003eTrue if the number is prime, false otherwise.\u003c/returns\u003e\r\n/// \u003cremarks\u003e\r\n/// This method is not efficient, but it is simple and easy to understand.\r\n/// It checks if the number is divisible by any number from 2 to the square root of the number.\r\n/// If it is divisible by any of these numbers, then it is not prime.\r\n/// If it is not divisible by any of these numbers, then it is prime.\r\n/// \u003c/remarks\u003e\r\nprivate bool IsPrime(int num)\r\n{\r\n    if (num \u003c 2) return false;\r\n    for (int i = 2; i \u003c= Math.Sqrt(num); i++)\r\n    {\r\n        if (num % i == 0) return false;\r\n    }\r\n    return true;\r\n}\r\n```   \r\n\r\n2. GetPrimesUpTo() - which calls IsPrime()\r\n```C#\r\n/// \u003csummary\u003e\r\n/// Get all prime numbers up to a given number.\r\n/// \u003c/summary\u003e\r\n/// \u003cparam name=\"max\"\u003eThe maximum number to check.\u003c/param\u003e\r\n/// \u003creturns\u003eA list of all prime numbers up to the input.\u003c/returns\u003e\r\n/// \u003cremarks\u003e\r\n/// This method is not efficient, but it is simple and easy to understand.\r\n/// It checks if each number is prime using the IsPrime method.\r\n/// If the number is prime, it is added to the list of primes.\r\n/// Finally, the list of primes is returned.\r\n/// \u003c/remarks\u003e\r\nprivate List\u003cint\u003e GetPrimesUpTo(int max)\r\n{\r\n    var primes = new List\u003cint\u003e();\r\n    for (int num = 2; num \u003c= max; num++)\r\n    {\r\n        if (IsPrime(num))\r\n        {\r\n            primes.Add(num);\r\n        }\r\n    }\r\n    return primes;\r\n}\r\n```\r\n\r\n### Views/Home\r\n\r\n#### Index.cshtml\r\nPresents a form so the user can input a upper limit (a maximum) for the List\u003cint\u003e of primes as the result.\r\n\r\n#### Results.cshtml\r\nDisplays each of the elements (primes) in a new line up to the input of the Index.cshtml page.\r\n\r\nAlso provides a back button.\r\n\r\n### Program.cs\r\nThe only change made was:\r\n\r\n```C#\r\napp.MapControllerRoute(\r\n    name: \"default\",\r\n    pattern: \"{controller=Home}/{action=Index}/{id?}\");\r\n```\r\n\r\n## Publish to IIS on Windows Server\r\n\r\n### Preparing the project\r\n1. Build\r\nI personally suggest `C:\\projects\\server-cpu-stress` as the webapp directory.\r\n```bash\r\ndotnet build \u003cwebapp-directory\u003e\r\n```\r\n\r\n2. Publish\r\nChoose either:\r\n\r\na) Publishing without a path.\r\n```bash\r\ndotnet publish -c Release\r\n```\r\n\r\nb) Publishing in a specific path.\r\nThat may be `C:\\published\\server-cpu-stress`\r\n\r\n```bash\r\ndotnet publish -c Release -o \u003coutput-directory\u003e\r\n```\r\n\r\n### Running on IIS\r\n\r\n1. Add a new Website\r\n\r\nWith IIS open, right click on Sites ...\r\n\r\n![image](https://github.com/user-attachments/assets/5f9f389f-206a-42b1-8ef5-daac5a7ab36b)\r\n\r\n2. Set it up\r\n\r\nSet a name such as `server-cpu-stress`\r\n\r\n- If it's a new site, IIS might create a new `Application pool` (field to the right of the name) which will follow with the same name as you choose for your `Site name`. \r\n\r\n- Choose the path for the published webapp such as `C:\\published\\server-cpu-stress`.\r\n\r\n- Bind a port such as 80. Make sure there are rules to allow traffic from that port on Windows Defender Firewall's Ibound Rules. Added them as needed.\r\n\r\n![image-1](https://github.com/user-attachments/assets/278b4997-fb20-466f-8ca6-15e94b01fa27)\r\n\r\n3. Check its Application pool\r\n\r\n(LEFT) Click on Application Pools;\r\n\r\n(MIDDLE) Click on the name of your pool such as `server-cpu-stress`;\r\n\r\n(RIGHT) Click on `Basic settings`.\r\n\r\n![image-2](https://github.com/user-attachments/assets/66b763b2-3e4e-4c53-870b-1b94683cd9b4)\r\n\r\nAnd finally make sure your pool's `.NET CLR version` is set to `No Managed Code`\r\n\r\n![image-3](https://github.com/user-attachments/assets/8a6695e7-ef4d-4d4e-9bca-1687423e058e)\r\n\r\n## Serving with Nginx and revers proxy\r\n\r\n### Install .NET 8.0 SDK\r\n```bash\r\nsudo yum install -y dotnet-sdk-8.0\r\n```\r\n\r\n### Nginx\r\n\r\n#### Install\r\n```bash\r\nsudo dnf install nginx -y\r\n```\r\n\r\n#### Publish the webapp code\r\nPublishing without a path.\r\n```bash\r\ndotnet publish -c Release\r\n```\r\n\r\n#### Start Nginx\r\n```bash \r\nsudo systemctl start nginx\r\nsudo systemctl enable nginx\r\n```\r\n\r\n#### Configure the Nginx reverse proxy\r\nOpen the .congf file\r\n```bash\r\nsudo nano /etc/nginx/nginx.conf\r\n```\r\n\r\n```bash\r\nserver {\r\n    listen       80;                        # Port \r\n    server_name  00.000.000.00;             # Your public IP or domain\r\n\r\n    location / {\r\n        proxy_pass http://localhost:5000;   # Change the port to match your Kestrel app\r\n        proxy_http_version 1.1;\r\n        proxy_set_header Upgrade $http_upgrade;\r\n        proxy_set_header Connection 'upgrade';\r\n        proxy_set_header Host $host;\r\n        proxy_cache_bypass $http_upgrade;\r\n    }\r\n\r\n    error_page 404 /404.html;\r\n    location = /404.html {\r\n    }\r\n\r\n    error_page 500 502 503 504 /50x.html;\r\n    location = /50x.html {\r\n    }\r\n}\r\n```\r\n\r\n#### Restart\r\n```bash\r\nsudo systemctl restart nginx\r\n```\r\n\r\n#### Run locally\r\n```bash \r\ndotnet run --project server-cpu-stress.csproj\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeed0%2Fserver-cpu-stress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeed0%2Fserver-cpu-stress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeed0%2Fserver-cpu-stress/lists"}