在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cloudfoundry/gorouter开源软件地址:https://github.com/cloudfoundry/gorouter开源编程语言:Go 99.9%开源软件介绍:GorouterThis repository contains the source code for the Cloud Foundry L7 HTTP router. Gorouter is deployed by default with Cloud Foundry (cf-deployment) which includes routing-release as submodule.
Reporting issues and requesting featuresPlease report all issues and feature requests in cloudfoundry/routing-release. ContributingPlease read the contributors' guide and our Development Guide for Gorouter. DevelopmentThe following instructions may help you get started with gorouter. Prerequisites
SetupGorouter dependencies are managed with routing-release. Do not clone the gorouter repo directly; instead, follow instructions at https://github.com/cloudfoundry/routing-release#get-the-code (summarized below). git clone https://github.com/cloudfoundry/routing-release
cd routing-release
./scripts/update
cd src/code.cloudfoundry.org/gorouter Running TestsTests in this repo cannot be run on their own, only as part of Routing Release. Follow the instructions for running tests in docker in the routing release readme. BuildingBuilding creates an executable in the gorouter/ dir: go build InstallingInstalling creates an executable in the $GOPATH/bin dir: go install Start# Start NATS server in daemon mode
git clone https://github.com/nats-io/nats-server
cd nats-server/
go install
nats-server &
# Start gorouter
gorouter PerformanceSee [Routing Release 0.144.0 Release Notes] (https://github.com/cloudfoundry/routing-release/releases/tag/0.144.0) Dynamic Routing TableGorouters routing table is updated dynamically via the NATS message bus. NATS can be deployed via BOSH with (cf-deployment) or standalone using nats-release. To add or remove a record from the routing table, a NATS client must send register or unregister messages. Records in the routing table have a maximum TTL of 120 seconds, so clients must heartbeat registration messages periodically; we recommend every 20s. Route Registrar is a BOSH job that comes with Routing Release that automates this process. When deployed with Cloud Foundry, registration of routes for apps pushed to CF occurs automatically without user involvement. For details, see [Routes and Domains] (https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html). Registering Routes via NATSWhen the gorouter starts, it sends a The format of the {
"id": "some-router-id",
"hosts": ["1.2.3.4"],
"minimumRegisterIntervalInSeconds": 20,
"prunteThresholdInSeconds": 120
} After a If a component comes online after the router, it must make a NATS request called
The format of the {
"host": "127.0.0.1",
"port": 4567,
"tls_port": 1234,
"protocol": "http1",
"uris": [
"my_first_url.localhost.routing.cf-app.com",
"my_second_url.localhost.routing.cf-app.com"
],
"tags": {
"another_key": "another_value",
"some_key": "some_value"
},
"app": "some_app_guid",
"stale_threshold_in_seconds": 120,
"private_instance_id": "some_app_instance_id",
"isolation_segment": "some_iso_seg_name",
"server_cert_domain_san": "some_subject_alternative_name"
}
Additionally, if the Such a message can be sent to both the Deleting a RouteRoutes can be deleted with the ExampleCreate a simple app $ nohup ruby -rsinatra -e 'get("/") { "Hello!" }' & Send a register message $ nats-pub 'router.register' '{"host":"127.0.0.1","port":4567,"uris":["my_first_url.localhost.routing.cf-app.com","my_second_url.localhost.routing.cf-app.com"],"tags":{"another_key":"another_value","some_key":"some_value"}}'
Published [router.register] : '{"host":"127.0.0.1","port":4567,"uris":["my_first_url.localhost.routing.cf-app.com","my_second_url.localhost.routing.cf-app.com"],"tags":{"another_key":"another_value","some_key":"some_value"}}' See that it works! $ curl my_first_url.localhost.routing.cf-app.com:8081
Hello! Unregister the route $ nats-pub 'router.unregister' '{"host":"127.0.0.1","port":4567,"tls_port":1234,"uris":["my_first_url.localhost.routing.cf-app.com","my_second_url.localhost.routing.cf-app.com"]}'
Published [router.unregister] : '{"host":"127.0.0.1","port":4567,"tls_port":1234,"uris":["my_first_url.localhost.routing.cf-app.com","my_second_url.localhost.routing.cf-app.com"]}' See that the route is gone $ curl my_first_url.localhost.routing.cf-app.com:8081
404 Not Found: Requested route ('my_first_url.localhost.routing.cf-app.com') does not exist. If Note that if
Healthchecking from a Load BalancerTo scale Gorouter horizontally for high-availability or throughput capacity, you must deploy it behind a highly-available load balancer (F5, AWS ELB, etc). Gorouter has a health endpoint $ curl -v http://10.0.32.15:8080/health
* Trying 10.0.32.15..
* Connected to 10.0.32.15 (10.0.32.15) port 8080 (#0)
> GET /health HTTP/1.1
> Host: 10.0.32.15:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: private, max-age=0
< Expires: 0
< Date: Thu, 22 Sep 2016 00:13:54 GMT
< Content-Length: 3
< Content-Type: text/plain; charset=utf-8
<
ok
* Connection #0 to host 10.0.32.15 left intact DEPRECATED: Your load balancer can be configured to send an HTTP
healthcheck on port 80 with the $ curl -v -A "HTTP-Monitor/1.1" "http://10.0.32.15"
* Rebuilt URL to: http://10.0.32.15/
* Hostname was NOT found in DNS cache
* Trying 10.0.32.15...
* Connected to 10.0.32.15 (10.0.32.15) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: HTTP-Monitor/1.1
> Host: 10.0.32.15
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: private, max-age=0
< Expires: 0
< X-Vcap-Request-Id: 04ad84c6-43dd-4d20-7818-7c47595d9442
< Date: Thu, 07 Jan 2016 22:30:02 GMT
< Content-Length: 3
< Content-Type: text/plain; charset=utf-8
<
ok
* Connection #0 to host 10.0.32.15 left intact DEPRECATED: The InstrumentationThe Routing TableThe $ curl "http://someuser:[email protected]:8080/routes"
{
"api.catwoman.cf-app.com": [
{
"address": "10.244.0.138:9022",
"ttl": 0,
"tags": {
"component": "CloudController"
}
}
],
"dora-dora.catwoman.cf-app.com": [
{
"address": "10.244.16.4:60035",
"ttl": 0,
"tags": {
"component": "route-emitter"
}
},
{
"address": "10.244.16.4:60060",
"ttl": 0,
"tags": {
"component": "route-emitter"
}
}
]
} Because of the nature of the data present in properties:
router:
status:
password: zed292_bevesselled
port:
user: paronymy61-polaric If Or on the Gorouter VM under status:
port: 8080
user: some_user
pass: some_password MetricsThe Metrics response (click to expand)$ curl "http://someuser:[email protected]:8080/varz"
{
"bad_gateways": 0,
"bad_requests": 20,
"cpu": 0,
"credentials": [
"user",
"pass"
],
"droplets": 26,
"host": "10.0.32.15:8080",
"index": 0,
"latency": {
"50": 0.001418144,
"75": 0.00180639025,
"90": 0.0070607187,
"95": 0.009561058849999996,
"99": 0.01523927838000001,
"samples": 1,
"value": 5e-07
},
"log_counts": {
"info": 9,
"warn": 40
},
"mem": 19672,
"ms_since_last_registry_update": 1547,
"num_cores": 2,
"rate": [
1.1361328993362565,
1.1344545494448148,
1.1365784133171992
],
"requests": 13832,
"requests_per_sec": 1.1361328993362565,
"responses_2xx": 13814,
"responses_3xx": 0,
"responses_4xx": 9,
"responses_5xx": 0,
"responses_xxx": 0,
"start": "2016-01-07 19:04:40 +0000",
"tags": {
"component": {
"CloudController": {
"latency": {
"50": 0.009015199,
"75": 0.0107408015,
"90": 0.015104917100000005,
"95": 0.01916497394999999,
"99": 0.034486261410000024,
"samples": 1,
"value": 5e-07
},
"rate": [
0.13613289933245148,
0.13433569936308343,
0.13565885617276216
],
"requests": 1686,
"responses_2xx": 1684,
"responses_3xx": 0,
"responses_4xx": 2,
"responses_5xx": 0,
"responses_xxx": 0
},
"HM9K": {
"latency": {
"50": 0.0033354,
"75": 0.00751815875,
"90": 0.011916812100000005,
"95": 0.013760064,
"99": 0.013760064,
"samples": 1,
"value": 5e-07
},
"rate": [
1.6850238803894876e-12,
5.816129919395257e-05,
0.00045864309255845694
],
"requests": 12,
"responses_2xx": 6,
"responses_3xx": 0,
"responses_4xx": 6,
"responses_5xx": 0,
"responses_xxx": 0
},
"dea-0": {
"latency": {
"50": 0.001354994,
"75": 0.001642107,
"90": 0.0020699939000000003,
"95": 0.0025553900499999996,
"99": 0.003677146940000006,
"samples": 1,
"value": 5e-07
},
"rate": [
1.0000000000000013,
1.0000000002571303,
0.9999994853579043
],
"requests": 12103,
"responses_2xx": 12103,
"responses_3xx": 0,
"responses_4xx": 0,
"responses_5xx": 0,
"responses_xxx": 0
},
"uaa": {
"latency": {
"50": 0.038288465,
"75": 0.245610809,
"90": 0.2877324668,
"95": 0.311816554,
"99": 0.311816554,
"samples": 1,
"value": 5e-07
},
"rate": [
8.425119401947438e-13,
2.9080649596976205e-05,
0.00022931374141467497
],
"requests": 17,
"responses_2xx": 17,
"responses_3xx": 0,
"responses_4xx": 0,
"responses_5xx": 0,
"responses_xxx": 0
}
}
},
"top10_app_requests": [
{
"application_id": "063f95f9-492c-456f-b569-737f69c04899",
"rpm": 60,
"rps": 1
}
],
"type": "Router",
"uptime": "0d:3h:22m:31s",
"urls": 21,
"uuid": "0-c7fd7d76-f8d8-46b7-7a1c-7a59bcf7e286"
} Profiling the ServerThe Gorouter runs the debugserver, which is a wrapper around the go pprof tool. In order to generate this profile, do the following: # Establish a SSH tunnel to your server (not necessary if you can connect directly)
ssh -L localhost:8080:[INTERNAL_SERVER_IP]:17001 vcap@[BOSH_DIRECTOR]
# Run the profile tool.
go tool pprof http://localhost:8080/debug/pprof/profile Load BalancingThe Gorouter is, in simple terms, a reverse proxy that load balances between many backend instances. The default load balancing algorithm that Gorouter will use is a simple round-robin strategy. Gorouter will retry a request if the chosen backend does not accept the TCP connection. Round-RobinDefault load balancing algorithm that gorouter will use or may be explicitly set
in gorouter.yml Least-ConnectionThe Gorouter also supports least connection based routing and this can be enabled in gorouter.yml default_balancing_algorithm: least-connection Least connection based load balancing will select the endpoint with the least number of connections. If multiple endpoints match with the same number of least connections, it will select a random one within those least connections. NOTE: Gorouter currently only supports changing the load balancing strategy at the gorouter level and does not yet support a finer-grained level such as route-level. Therefore changing the load balancing algorithm from the default (round-robin) should be proceeded with caution. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论