Live data from Hacker News

Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

github.com

31–40 of 41 posts

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#31
post #8

Sometimes waiting for the address is not enough. For example, you might want to wait for a specific API enpoint to return 200 OK, or you might want to wait for database migrations to get applied. Is `is_ready` aiming to cover those cases in the future?

Interesting idea for a feature request. I would love to read a GitHub issue with your specific case so I can start investigating and think about how to solve a problem like this.

I considered starting to write myself a Rust "wait for it" app myself this past week with more features than the standard one. Not sure how I didn't come across yours during my initial search.

There could be some useful functionality that could be found in startup and health probe topics [1] in Kubernetes for example. But at least in that world, it may be easier, and more transparent, to plug in a startup bash script to run before the main app. For example the Postgres Docker image [2] will run any scripts that may be mounted in a docker-entrypoint-initdb.d directory before starting the server. So putting a bash script in a ConfigMap that gets used as a disk volume, could be easier that downloading/auditing a binary "wait for it" container image.

[1] https://kubernetes.io/docs/tasks/configure-pod-container/con...

[2] https://hub.docker.com/_/postgres

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#32

Earlier quoted context omitted.

Can you suggest to me one way for an API service to wait for a database to accept connections to run the database migrations without the API depending on the liveness of the database to start up?

Start the server and respond 503 every time when your database and other dependencies are not ready. Couldn’t be easier.

Many people have the following setup in docker-compose.yml file.

version: '3' services: mysql: image: mysql:8.0

  app:
    build: .
    command: is_ready --timeout 10 --addr mysql:3306 -- 
For cases like this, returning 503 every time the database is not ready, is not very convenient.

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#33
With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well!

I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead.

[0] https://github.com/peter-evans/docker-compose-healthcheck

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#34

With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well! I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead. [0] https://github.com/peter-evans/docker-compose-healthcheck

Healthchecks are a great way to achieve this.

As this repository mentions, this is the example using PostgreSQL.

depends_on: postgres-database: condition: service_healthy

healthcheck: test: ["CMD-SHELL", "pg_isready"] interval: 10s timeout: 5s retries: 5

However, PostgreSQL has already a command for this called pg_isready.

How is this going to work for other cases such as MySQL?

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#35
post #15

Alternative: write your applications to not depend on the liveness of other services to start up. Your ops will thank you.

Can you suggest to me one way for an API service to wait for a database to accept connections to run the database migrations without the API depending on the liveness of the database to start up?

I think the pragmatic answer is you should wait for your database to be live before starting up. One just wants to lean on the side of depending on a few critical services rather than all potentially-utlizied application services.

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#36

With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well! I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead. [0] https://github.com/peter-evans/docker-compose-healthcheck

Interesting. And it works for external HTTP services as well, I presume, right?

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#37

With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well! I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead. [0] https://github.com/peter-evans/docker-compose-healthcheck

Healthchecks are a great way to achieve this. As this repository mentions, this is the example using PostgreSQL. depends_on: postgres-database: condition: service_healthy healthcheck: test: ["CMD-SHELL", "pg_isready"] interval: 10s timeout: 5s retries: 5 However, PostgreSQL has already a command for this called pg_isready. How is this going to work for other cases such as MySQL?

> How is this going to work for other cases such as MySQL?

You could do a query like SHOW DATABASES as a healthcheck for mysql.

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#38
post #36

With Docker compose, there is a more idiomatic way to achieve this with zero dependencies using healthchecks[0]. Works well! I used wait_for_it.sh for the purpose described in the OP until I found healtchecks could be used instead. [0] https://github.com/peter-evans/docker-compose-healthcheck

Interesting. And it works for external HTTP services as well, I presume, right?

A shell command, so curl would work

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#39
"poll every N seconds" for readiness checks is an anti-pattern. The problem is that latency cascades. A dependency chain of M services will have an end-to-end latency of N*M in the worst case and (N*M/2) in the average case, if they all rely on polling to check that the next service is ready.

You should instead rely on backpressure to signal readiness. A service accepts connections immediately, and only blocks the client when the service has to block on something else to procure a response. Systemd takes this approach with UNIX sockets - it creates all the UNIX sockets for each service, and then starts all the services in parallel. The socket buffers queue the messages so that clients can send messages to services that haven't yet started, and the OS scheduler will saturate the available CPU/IO so that the startup of all the services are maximally parallelized.

Obviously, this is not always feasible, especially in cases where you don't control the service(s) you depend on. But to the extent that you do, relying on backpressure instead of polling can markedly improve end-to-end latency.

Re: Show HN: Is_ready – Wait for many services to become available – 0 Dependencies

#40
post #6

Earlier quoted context omitted.

I took the statement to imply no runtime dependencies, as no compile-time dependencies doesn’t really make sense.

The Linux kernel itself to handle the syscalls is probably also implied in this.

glibc ftw
Post reply on HN