News for hackers. Stuff that matters.

thezviad

Re:Uber Go Style Guide on Friday October 11, 2019 @05:30PM (#21228664)
the way to do is to pass context all the way through, until the other thing you are waiting on uses up no resources.

so in your example it should be done like this: ch <- workFor(ctx, in)

and the 'workFor' function should be the one that gets canceled with the context.

Deep down at the very end, you would have select statement with '<-ctx.Done()' and something else that doesn't need canceling (if it needs canceling it should have taken context too).

Of course the world isn't perfect and not everything takes context right now (even in standard library), so you do have to do some workarounds every once in a while.

Re:About Database Connection Pool Sizing on Monday November 12, 2018 @12:28PM (#18433993)
Start of every new transaction does a scan of all connected sessions (including idle) ones. I am pretty sure this is true in 5.6 too, and most likely in newer versions too. So if the queries that you are issuing are large or the total connection count is <10k it is not going to be problem or even noticeable. But if you have lots of small and fast queries and have idle connections >100k you will definitely have significant perf issues because of the idle connections. 100k is a big number for sure, but it is definitely possible to hit those limits if the application layer is done in languages like node, ruby, python, when you need to run many application processes since each app process can't properly utilize more than single CPU core. Thus you end up having a lot of separate processes each with its own connection pool to the backing database.

As for per-user limits, those resource limits aren't that useful for stability. Setting max simultaneous connections is not as useful, because you don't know how many of those are idle or active. You want limits on active sessions that are actually doing work, not how many idle sessions exist. Unless of course you plan on not doing any session reuse, and always make a new session for each transaction, which will lead to huge other set of performance issues because establishing new sessions is pretty expensive.

As for the other "per hour" limits, they are also not useful to provide protections against burst traffic which is a common way a MySQL instance can enter into a bad feedback loop and slow down to crawl. (Example: there is a burst traffic from one use case, creating lots of new active transactions at the same time, because of that, MySQL perf slows down, so now you have even more active transactions because everything is slower, which leads to even more slow down, so even after the burst traffic is over, database is in a bad state since now you continuously have too many active transactions and it is unable to recover on its own to handle the same steady state traffic as it was able to handle before the burst).

Re:About Database Connection Pool Sizing on Monday November 12, 2018 @10:37AM (#18433185)
I am not as familiar with Postgres as with MySQL, but in this case they would most likely be similarly deficient.

Databases like MySQL and Postgres have optimized on disk storage engines and query planners, but the other parts that are needed for true high availability, and stability at scale are definitely lacking in both.

Re:About Database Connection Pool Sizing on Monday November 12, 2018 @10:17AM (#18433056)
This article would be better if it was called "connection pool sizing for MySQL". If you had a better database, you would have to worry way less about configuring pool size on the clients.

The proper way to do this would be for the server (i.e. database) itself to have maximum active transaction limits and ways to setup quotas for different use cases, especially as your company gets large, and you have many different use cases mixed in the same database. Basically the queue should exist mostly on the server, and clients shouldn't have to worry about overwhelming the server. If server queue gets large, server should start rejecting requests faster, and clients would do a backoff and retry with a delay based on that instead. This also makes sure server can't be easily overworked if you have one misconfigured and misbehaving client.

Lot of issues with many idle connections in MySQL are specific to MySQL itself and its implementation. In MySQL the perf drops not only when you have many active transaction, but even when you have many just many connected idle sessions. This is why there are tons of different random "MySQL Connection Proxy" projects that exist in the open source.

Re:In search of a simple consensus algorithm on Friday March 17, 2017 @02:33PM (#13896634)
Good to see more leaderless consensus protocol implementations and that RAFT isn't be all and end all of all consensus problems.

One advantage not mentioned in the article, of leader based consensus algorithms is the ability to more easily implement read leases for faster reads.

Read leases can allow for fresh reads without having to run them through the quorum protocol, by trading off availability (due to leader failure) and also correctness in certain edge cases (since read leases will depend on ability for individual machines to measure time delta with reasonable accuracy, which may not be true on some weird VM scenarios).