{"id":17209937,"url":"https://github.com/brocaar/l3dsr-hash-balancer","last_synced_at":"2025-04-13T22:36:52.041Z","repository":{"id":30582688,"uuid":"34137754","full_name":"brocaar/l3dsr-hash-balancer","owner":"brocaar","description":"Layer-3 Direct Server Return load balancer prototype","archived":false,"fork":false,"pushed_at":"2015-10-27T18:38:38.000Z","size":151,"stargazers_count":28,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T14:41:15.100Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brocaar.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":"2015-04-17T20:09:43.000Z","updated_at":"2024-11-10T07:42:35.000Z","dependencies_parsed_at":"2022-08-30T06:32:23.215Z","dependency_job_id":null,"html_url":"https://github.com/brocaar/l3dsr-hash-balancer","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/brocaar%2Fl3dsr-hash-balancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocaar%2Fl3dsr-hash-balancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocaar%2Fl3dsr-hash-balancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocaar%2Fl3dsr-hash-balancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brocaar","download_url":"https://codeload.github.com/brocaar/l3dsr-hash-balancer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248792649,"owners_count":21162402,"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":[],"created_at":"2024-10-15T02:52:54.010Z","updated_at":"2025-04-13T22:36:51.992Z","avatar_url":"https://github.com/brocaar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Layer-3 Direct Server Return load balancer prototype\n\n**note this is proof-of-concept project, do not use this in production**\n\nThis is a prototype for a L3-DSR hash based load balancer. For a client I was\nresearching if we could improve its CDN (for streaming content) by using\na hash-based loadbalancer with the capability of using Layer-3 based Direct\nServer Return (so that returning traffic is bypassing the loadbalancer).\n\nThis codebase only implements a naive balancer application which:\n\n1. creates a handshake with the client\n2. inspects the first packet to determine which server to route the traffic to\n3. syncs the TCP handshake with the packetbridge application\n4. forwards all further TCP traffic to the packetbridge\n\nBy using the DSCP field in the IPv4 header, the loadbalancer identifies itself\nto the packetbride.\n\nThe packetbridge application:\n\n1. receives TCP packets from the balancer application\n2. creates (for new connections) a handshake with the backend (e.g. NGINX)\n3. modifies the incoming traffic so that it matches with the TCP handshake\n   of the backend\n4. modifies outgoing traffic so that it matches with the TCP handshake of\n   the client.\n\nThe packetbride will use the loadbalancer IP address (it knows because of the\nDSCP field) for outgoing traffic, so that outgoing traffic bypasses the\nloadbalancer.\n\n## How to use\n\nThe easiest way to play with this project is to setup a Vagrant environment.\nRunning ``vagrant up`` will setup two boxes, one for the balancer, the other\nfor the backend.\n\nNote that all cli argument have defaults that matches the Vagrant\nenvironment.\n\n### starting the balancer\n\nRun the following commands to start the balancer (within the Vagrant\nenvironment). \n\n```\nvagrant ssh balancer\ncd src/github.com/brocaar/l3dsr-hash-balancer\ngo get ./...\nmake\nsudo ./bin/balancer\n```\n\nThe balancer box has one interface ``192.168.33.10`` on which it listens for\nincoming requests.\n\n\n### starting the packetbridge / backend\n\nRun the following commands to start the packetbridge (within the Vagrant\nenvironment).\n\n```\nvagrant ssh backend\ncd src/github.com/brocaar/l3dsr-hash-balancer\nsudo ./bin/packetbridge\n```\n\nThe backend box has two interfaces. On ``192.168.33.20`` it listens for incoming\npackets from the balancer. On ``192.168.33.30`` NGINX is running.\n\n### making requests\n\nNow that both applications are running, you can make a request to\n``http://192.168.33.10/``. This will:\n\n* Create a TCP handshake between you and the balancer (``.10``)\n* The balancer (``.10``) will sync your TCP handshake with the packetbridge\n  (``.20``)\n* The packetbridge (``.20``) will create a TCP handshake with the backend\n  (NGINX on ``.30``).\n* The packetbridge will start forwarding your packets to NGIXN (``.30``) and\n  the packets from NGINX to you (by using the ``.10`` source ip). Your HTTP\n  client will think that all packets came from the balancer :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrocaar%2Fl3dsr-hash-balancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrocaar%2Fl3dsr-hash-balancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrocaar%2Fl3dsr-hash-balancer/lists"}