{"id":13612891,"url":"https://github.com/hnes/cpuworker","last_synced_at":"2025-04-12T19:06:04.371Z","repository":{"id":57656581,"uuid":"368232315","full_name":"hnes/cpuworker","owner":"hnes","description":"cpuworker - A Customized Goroutine Scheduler over Golang Runtime","archived":false,"fork":false,"pushed_at":"2022-02-08T14:05:51.000Z","size":569,"stargazers_count":168,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-07T21:41:24.857Z","etag":null,"topics":["golang","goroutine","latency","scheduler"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hnes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-17T15:19:26.000Z","updated_at":"2024-08-21T01:12:46.000Z","dependencies_parsed_at":"2022-08-26T05:11:37.410Z","dependency_job_id":null,"html_url":"https://github.com/hnes/cpuworker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hnes%2Fcpuworker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hnes%2Fcpuworker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hnes%2Fcpuworker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hnes%2Fcpuworker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hnes","download_url":"https://codeload.github.com/hnes/cpuworker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224742353,"owners_count":17362232,"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":["golang","goroutine","latency","scheduler"],"created_at":"2024-08-01T20:00:36.005Z","updated_at":"2024-11-15T07:15:35.225Z","avatar_url":"https://github.com/hnes.png","language":"Go","readme":"# cpuworker\n\n## Status\n\nWorking in process.\n\n## Proposal For Go\n\n[proposal: runtime/scheduler: it is time to bring Go a better scheduler maybe like Linux Kernel's CFS](https://github.com/golang/go/issues/51071)\n\n## Run the Demo\n\nMake sure the GOMAXPROCS is bigger than 1 and there is at least `GOMAXPROCS` physical OS threads available.\n\nRun the [example/demo.go](example/demo.go).\n\n```bash\n# feel free to tune the parameters below if you like\n\n# cmd 1\nwhile true; do sleep 1;ab -s10000000 -c 10 -n 60 http://127.0.0.1:8080/delay1ms; done\n\n# cmd 2\nwhile true; do sleep 1;ab -s10000000 -c 10 -n 60 http://127.0.0.1:8080/checksumWithoutCpuWorker; done\n\n# cmd 3\nwhile true; do sleep 1;ab -s10000000 -c 10 -n 60 http://127.0.0.1:8080/checksumWithCpuWorker; done\n\n# cmd 4\nwhile true; do sleep 1;ab -s10000000 -c 10 -n 60 http://127.0.0.1:8080/checksumSmallTaskWithCpuWorker; done\n```\n\nStep 1: Killall already existing cmd `x`, then run the cmd 1.\n\nStep 2: Killall already existing cmd `x`, then run the cmd 1 and cmd 2 simultaneously.\n\nStep 3: Killall already existing cmd `x`, then run the cmd 1 and cmd 3 simultaneously.\n\nStep 4: Killall already existing cmd `x`, then run the cmd 1, cmd 3 and cmd 4 simultaneously.\n\nPlease watch the latency which cmd 1 and cmd 4 yields carefully at every step and then you would catch the difference :-D\n\n## Test Result On AWS\n\nThe server [example/demo.go](example/demo.go) is running at an aws instance `c5d.12xlarge` and with the env `GOMAXPROCS` set to 16.\n\n```bash\n$ GOMAXPROCS=16 ./cpuworker-demo\n\nGOMAXPROCS: 16 cpuWorkerMaxP: 12 length of crc32 bs: 262144\n```\n\nThe benchmark tool is running at an aws instance `c5d.4xlarge`. The two machine is running at a same cluster placement group.\n\n```bash\n# please complete the server IP\nSeverIP=x.x.x.x\n\n# cmd 1\nwhile true; do sleep 1;ab -s10000000 -c 100 -n 60000 http://$SeverIP:8080/delay1ms; done\n\n# cmd 2\nwhile true; do sleep 1;ab -s10000000 -c 100 -n 10000 http://$SeverIP:8080/checksumWithoutCpuWorker; done\n\n# cmd 3\nwhile true; do sleep 1;ab -s10000000 -c 100 -n 10000 http://$SeverIP:8080/checksumWithCpuWorker; done\n\n# cmd 4\nwhile true; do sleep 1;ab -s10000000 -c 100 -n 10000 http://$SeverIP:8080/checksumSmallTaskWithCpuWorker; done\n```\n\nStep 1: Killall already existing cmd `x`, then run the cmd 1 (run the standalone benchmark of delay1ms).\n\n```bash\n$ ab -s10000000 -c 100 -n 60000 http://$SeverIP:8080/delay1ms\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1879490 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 172.31.47.63 (be patient)\nCompleted 1000 requests\nCompleted 2000 requests\nCompleted 3000 requests\nCompleted 4000 requests\nCompleted 5000 requests\nCompleted 6000 requests\nCompleted 7000 requests\nCompleted 8000 requests\nCompleted 9000 requests\nCompleted 10000 requests\nFinished 10000 requests\n\nServer Software:\nServer Hostname:        172.31.47.63\nServer Port:            8080\n\nDocument Path:          /delay1ms\nDocument Length:        37 bytes\n\nConcurrency Level:      100\nTime taken for tests:   0.225 seconds\nComplete requests:      10000\nFailed requests:        1066\n   (Connect: 0, Receive: 0, Length: 1066, Exceptions: 0)\nTotal transferred:      1538813 bytes\nHTML transferred:       368813 bytes\nRequests per second:    44413.06 [#/sec] (mean)\nTime per request:       2.252 [ms] (mean)\nTime per request:       0.023 [ms] (mean, across all concurrent requests)\nTransfer rate:          6674.16 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.2      0       1\nProcessing:     1    2   0.4      2       4\nWaiting:        1    2   0.4      1       4\nTotal:          1    2   0.5      2       5\nERROR: The median and mean for the waiting time are more than twice the standard\n       deviation apart. These results are NOT reliable.\n\nPercentage of the requests served within a certain time (ms)\n  50%      2\n  66%      2\n  75%      2\n  80%      2\n  90%      3\n  95%      3\n  98%      4\n  99%      4\n 100%      5 (longest request)\n```\n\nStep 2: Killall already existing cmd `x`, then run the cmd 1 and cmd 2 simultaneously (run the benchmark of delay1ms with a very heavy cpu load without cpuworker).\n\nCurent CPU load of the server side (and please note that the load average is already reaching the `GOMAXPROCS`, i.e. 16 in this case):\n\n![step2-server-load](docs/img/step2-server-load.png)\n\n```bash\n$ ab -s10000000 -c 100 -n 60000 http://$SeverIP:8080/delay1ms\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1879490 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 172.31.47.63 (be patient)\nCompleted 1000 requests\nCompleted 2000 requests\nCompleted 3000 requests\nCompleted 4000 requests\nCompleted 5000 requests\nCompleted 6000 requests\nCompleted 7000 requests\nCompleted 8000 requests\nCompleted 9000 requests\nCompleted 10000 requests\nFinished 10000 requests\n\nServer Software:\nServer Hostname:        172.31.47.63\nServer Port:            8080\n\nDocument Path:          /delay1ms\nDocument Length:        38 bytes\n\nConcurrency Level:      100\nTime taken for tests:   31.565 seconds\nComplete requests:      10000\nFailed requests:        5266\n   (Connect: 0, Receive: 0, Length: 5266, Exceptions: 0)\nTotal transferred:      1553977 bytes\nHTML transferred:       383977 bytes\nRequests per second:    316.80 [#/sec] (mean)\nTime per request:       315.654 [ms] (mean)\nTime per request:       3.157 [ms] (mean, across all concurrent requests)\nTransfer rate:          48.08 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.1      0       1\nProcessing:    50  314  99.3    293    1038\nWaiting:       11  305 102.5    292    1038\nTotal:         50  314  99.3    293    1038\n\nPercentage of the requests served within a certain time (ms)\n  50%    293\n  66%    323\n  75%    353\n  80%    380\n  90%    454\n  95%    504\n  98%    604\n  99%    615\n 100%   1038 (longest request)\n```\n\nStep 3: Killall already existing cmd `x`, then run the cmd 1 and cmd 3 simultaneously (run the benchmark of delay1ms with a very heavy cpu load with cpuworker).\n\nCurent CPU load of the server side (and please note that the load average is near the `cpuWorkerMaxP`, i.e. 12 in this case, and you could set this parameter by yourself):\n\n![step3-server-load](docs/img/step3-server-load.png)\n\n```bash\n$ ab -s10000000 -c 100 -n 60000 http://$SeverIP:8080/delay1ms\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1879490 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 172.31.47.63 (be patient)\nCompleted 1000 requests\nCompleted 2000 requests\nCompleted 3000 requests\nCompleted 4000 requests\nCompleted 5000 requests\nCompleted 6000 requests\nCompleted 7000 requests\nCompleted 8000 requests\nCompleted 9000 requests\nCompleted 10000 requests\nFinished 10000 requests\n\n\nServer Software:\nServer Hostname:        172.31.47.63\nServer Port:            8080\n\nDocument Path:          /delay1ms\nDocument Length:        37 bytes\n\nConcurrency Level:      100\nTime taken for tests:   0.234 seconds\nComplete requests:      10000\nFailed requests:        1005\n   (Connect: 0, Receive: 0, Length: 1005, Exceptions: 0)\nTotal transferred:      1538877 bytes\nHTML transferred:       368877 bytes\nRequests per second:    42655.75 [#/sec] (mean)\nTime per request:       2.344 [ms] (mean)\nTime per request:       0.023 [ms] (mean, across all concurrent requests)\nTransfer rate:          6410.35 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.2      0       1\nProcessing:     1    2   0.5      2       4\nWaiting:        1    2   0.4      2       4\nTotal:          1    2   0.5      2       5\n\nPercentage of the requests served within a certain time (ms)\n  50%      2\n  66%      2\n  75%      2\n  80%      3\n  90%      3\n  95%      4\n  98%      4\n  99%      4\n 100%      5 (longest request)\n```\n\nStep 4: Killall already existing cmd `x`, then run the cmd 1, cmd 3 and cmd 4 simultaneously (run the benchmark of delay1ms and checksumSmallTaskWithCpuWorker with a very heavy cpu load with cpuworker).\n\nCurent CPU load of the server side (and please note that the load average is near the `cpuWorkerMaxP`, i.e. 12 in this case, and you could set this parameter by yourself):\n\n![step4-server-load](docs/img/step4-server-load.png)\n\n```bash\n$ ab -s10000000 -c 100 -n 60000 http://$SeverIP:8080/delay1ms\n\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1879490 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 172.31.47.63 (be patient)\nCompleted 1000 requests\nCompleted 2000 requests\nCompleted 3000 requests\nCompleted 4000 requests\nCompleted 5000 requests\nCompleted 6000 requests\nCompleted 7000 requests\nCompleted 8000 requests\nCompleted 9000 requests\nCompleted 10000 requests\nFinished 10000 requests\n\n\nServer Software:\nServer Hostname:        172.31.47.63\nServer Port:            8080\n\nDocument Path:          /delay1ms\nDocument Length:        37 bytes\n\nConcurrency Level:      100\nTime taken for tests:   0.238 seconds\nComplete requests:      10000\nFailed requests:        1038\n   (Connect: 0, Receive: 0, Length: 1038, Exceptions: 0)\nTotal transferred:      1538857 bytes\nHTML transferred:       368857 bytes\nRequests per second:    42031.11 [#/sec] (mean)\nTime per request:       2.379 [ms] (mean)\nTime per request:       0.024 [ms] (mean, across all concurrent requests)\nTransfer rate:          6316.39 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.2      0       1\nProcessing:     1    2   0.5      2       5\nWaiting:        1    2   0.4      1       5\nTotal:          1    2   0.6      2       5\nERROR: The median and mean for the waiting time are more than twice the standard\n       deviation apart. These results are NOT reliable.\n\nPercentage of the requests served within a certain time (ms)\n  50%      2\n  66%      2\n  75%      2\n  80%      3\n  90%      3\n  95%      4\n  98%      4\n  99%      4\n 100%      5 (longest request)\n \n$ ab -s10000000 -c 100 -n 10000 http://$SeverIP:8080/checksumSmallTaskWithCpuWorker\n\nThis is ApacheBench, Version 2.3 \u003c$Revision: 1879490 $\u003e\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking 172.31.47.63 (be patient)\nCompleted 1000 requests\nCompleted 2000 requests\nCompleted 3000 requests\nCompleted 4000 requests\nCompleted 5000 requests\nCompleted 6000 requests\nCompleted 7000 requests\nCompleted 8000 requests\nCompleted 9000 requests\nCompleted 10000 requests\nFinished 10000 requests\n\n\nServer Software:\nServer Hostname:        172.31.47.63\nServer Port:            8080\n\nDocument Path:          /checksumSmallTaskWithCpuWorker\nDocument Length:        71 bytes\n\nConcurrency Level:      100\nTime taken for tests:   0.469 seconds\nComplete requests:      10000\nFailed requests:        9157\n   (Connect: 0, Receive: 0, Length: 9157, Exceptions: 0)\nTotal transferred:      1889624 bytes\nHTML transferred:       719624 bytes\nRequests per second:    21333.56 [#/sec] (mean)\nTime per request:       4.687 [ms] (mean)\nTime per request:       0.047 [ms] (mean, across all concurrent requests)\nTransfer rate:          3936.76 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.3      0       2\nProcessing:     1    4   3.3      3      13\nWaiting:        1    4   3.3      3      13\nTotal:          2    5   3.4      3      13\n\nPercentage of the requests served within a certain time (ms)\n  50%      3\n  66%      4\n  75%      6\n  80%      9\n  90%     11\n  95%     11\n  98%     12\n  99%     12\n 100%     13 (longest request)\n```\n\nAt step 4, the latency of `checksumSmallTaskWithCpuWorker` is around 10ms, that is because:\n\n- the DefaultMaxTimeSlice of cpuworker is 10ms (feel free to tune it if you like)\n- cpuworker's scheduler thinks the new task always has a higher priority than current running and suspended tasks, so if the running tasks reach its MaxTimeSlice limit, the scheduler will suspend it at checkpoint and let the new task to run as soon as possible\n\n## Contributing\n\nWelcome to contribute 🎉🎉🎉\n\nBefore your pull request is merged, you must sign the [Developer Certificate of Origin](https://developercertificate.org/). Please visit the [DCO](https://github.com/apps/dco) for more information. Basically you add the `Signed-off-by: Real Name \u003ce@mail.addr\u003e` inside the commit message to claim all your contribution adheres the requirements inside the [DCO](https://github.com/apps/dco).\n\n## Copyright and License\n\nCopyright (C) 2021, by the cpuworker Authors\n\nUnless otherwise noted, the cpuworker source files are distributed under the Apache License Version 2.0. See the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhnes%2Fcpuworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhnes%2Fcpuworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhnes%2Fcpuworker/lists"}