{"id":21441634,"url":"https://github.com/ynathan/throttle-throttle-my-threads","last_synced_at":"2025-10-07T01:58:16.879Z","repository":{"id":223721618,"uuid":"287246567","full_name":"YNathan/throttle-throttle-my-threads","owner":"YNathan","description":null,"archived":false,"fork":false,"pushed_at":"2020-11-27T16:29:07.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-28T15:53:17.264Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/YNathan.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}},"created_at":"2020-08-13T10:15:34.000Z","updated_at":"2022-04-19T15:35:44.000Z","dependencies_parsed_at":"2024-02-21T18:56:21.787Z","dependency_job_id":"a3fb2bfc-be61-468f-9fd1-d7fd05467a32","html_url":"https://github.com/YNathan/throttle-throttle-my-threads","commit_stats":null,"previous_names":["ynathan/throttle-throttle-my-threads"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/YNathan/throttle-throttle-my-threads","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YNathan%2Fthrottle-throttle-my-threads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YNathan%2Fthrottle-throttle-my-threads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YNathan%2Fthrottle-throttle-my-threads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YNathan%2Fthrottle-throttle-my-threads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YNathan","download_url":"https://codeload.github.com/YNathan/throttle-throttle-my-threads/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YNathan%2Fthrottle-throttle-my-threads/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278708009,"owners_count":26031932,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-23T01:39:33.560Z","updated_at":"2025-10-07T01:58:16.842Z","avatar_url":"https://github.com/YNathan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Throttle Throttle My Threads\n\n# problem\n\n1. multiple users submit individual requests into the system, each in a different volume and\nrate (e.g. user Alice submits 1000 requests every minute, while user Bob submits 5 requests\nevery second, etc.).\n2. Each user’s requests need to be processed in the order by which they were submitted, but\nthere is no order between different users. For example, it is possible that user Alice’s\nrequests, which have been submitted at 9:00am will be handled – in order – only after user\nBob’s requests, which have been submitted at 9:01am.\nSince there is a variance in volume and rate between the users, the system should\npractice fairness in handling the request of the different users, so that handling user Alice’s\nrequests will not starve the other users.\n\n\n# solution\n\ni choose to have a ConcurrentHashMap \n  - the key will be the userId \n  - the value is an object that will mangae his own request\n  \nand like so every request that will be handle will be added to the write segment, and because it is a ConcurrentHashMap we will have lock on every segment it mean that a user can send 500 requests and in parralel second user can send 50 and both will be in separeted thread; \n\nlike so we handle the first part every user will have a diferance process\n\n\nnow lets go more deep\n\n  - a request wat handled\n  - a thread \"HandlerForUser\" will start for the request\n  - then we will check if it the user is registred in the map if yes it mean that he have more requests in process\n  - if no we will add to the map with the vlaue of a new \"RequestManager\"\n  - then we will add the request to the \"weaitingRequest\" list in the \"RequestManager\" by adding to a\n  internal hashtable list that will stor the rate a key and the request a value\n \nand now for the second fun part\n\n    - we will synchronize a section on the userId request\n    - then we calling the handellingRequest function\n    the function will get the lowest rate for userId (the lowest is the most importent like in c++ mutex and staff....)\n    the function will start running over the waitingRequest list for the current lowest rate\n    and for each will do the task desired and move to done request list (for our nice printer therad) in general we don't need this he will incrace the stack memory\n    - then will remove from the weiting request at the this rate\n    and if the awaiting request list is not wmpty will recursively rerun the function \n\n# Tests\ni sended a bulk of requests\n\n    the 2 first request is for user 1 with rate of 2 and for rate 5;\n    then i send a bulk of other requests for  deiferat users\n    in middle i add more one request for the user 1 for rate of 1\n    the n more bulk of users staff\n    and then again for user 1 2 request one of rate 0 and one of rate 3\n    \nso for user 1 the follow rate was sended 2,5,1,0,3\n    \nthe requests suppose to be handlled in the follow order 2 because its the first\n    but because the thread of user 1 is blocked on the request with rate 3\n    in paralle will be added to the list 5,1,0,3\n    so the result will be 0 then 1 then 3 then 5\n    so the ouput will be 2,0,1,3,5\n    \n # classes  \nHandler \n\n    the ConcurrentHashMap userId as key UserRequestManager as value\n    the handleRequest here is our stating point reciving the request\n    int the constrator a thread will run on the done requests so we can investigate what happen\nMapHelper\n\n    in the Constractor will start a new thread\n    the run methode that will work on the user request\n    \nUserRequestManager\n\n    an hashtable of the rate request a key and an list of requests as value\n    an arraylist of done requests\n    newRequest function will add to the waitinglist hashtable at the right rate\n    getLowestRateTheMostImportent function running over the keys in the waiting list request hastable  and return the lowest value\n    handleRequestInRateOrder here the task will produced\n    \n\n    \n    \n    \n\n\n\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynathan%2Fthrottle-throttle-my-threads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fynathan%2Fthrottle-throttle-my-threads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynathan%2Fthrottle-throttle-my-threads/lists"}