6,698 karma · joined Jul 18, 2012 (14y ago) · 1,967 submissions
Backend-focused full-stack engineer with 8+ years of experience, mostly focused on Go, Rust, and TypeScript, but open to other options.
Resume: https://drive.google.com/file/d/1VNC272B3n7ZEfppMHkm2wGgaINwYl4Av/view
comment 8y ago · link · parent
If your application gets bottlenecked by the number of connections in your pool, it's easy enough to increase the number, but the more independent pools you have, the more overprovisioned connections (connected but not being used) you will have scattered throughout those pools. It's also usually possible to run a connection pool without an upper limit, if you trust your database to handle large number of connections gracefully.
Rust and Go's connection poolers will also automatically scale down the connection pool when connections are idle for a given period of time, which is nice.
I can't think of any nightmares or headaches that I've encountered with those connection poolers. It all "Just Works"... except for PgBouncer, the ultimate connection pooler. PgBouncer doesn't work with prepared statements or transactions unless you run it in transaction mode, and then you have to run every query in a transaction to use prepared statements.
I'm definitely not suggesting that you try to serve 1000 concurrent requests with 10 connections or something silly like that, but that is what often happens when you get large Ruby deployments which would attempt to establish more connections than Postgres can handle, so you route them through PgBouncer where a small fraction of the number of connections exists.
But, this is pretty off-topic at this point. I didn't mean to point the conversation in this direction.
comment 8y ago · link · parent
But, I appreciate the addendum.
comment 8y ago · link · parent
The results:
1 switcher: 14_289_797.08 yields/sec
2 switchers: 5_866_478.94 yields/sec
3 switchers: 4_832_941.33 yields/sec
4 switchers: 4_604_051.57 yields/sec
5 switchers: 4_268_906.99 yields/sec
6 switchers: 3_982_688.58 yields/sec
7 switchers: 3_799_103.41 yields/sec
8 switchers: 3_673_094.58 yields/sec
9 switchers: 3_513_868.07 yields/sec
10 switchers: 3_351_813.00 yields/sec
11 switchers: 3_325_754.64 yields/sec
12 switchers: 3_150_383.56 yields/sec
13 switchers: 3_037_539.31 yields/sec
14 switchers: 2_435_807.77 yields/sec
15 switchers: 2_326_201.72 yields/sec
16 switchers: 2_275_610.57 yields/sec
64 switchers: 2_366_303.83 yields/sec
256 switchers: 2_400_782.51 yields/sec
512 switchers: 2_408_757.26 yields/sec
1024 switchers: 2_418_661.29 yields/sec
4096 switchers: 2_460_257.29 yields/sec
Underscores and alignment added for legibility.It looks like the context switching speed when you have a single Goroutine just completely outperforms any of the benchmark numbers that have been posted here for Python or Ruby, as would be expected, and it still outperforms the others even when running 256 yielding tasks for every logical core.
The cost of switching increased more with the number of goroutines than I would have expected, but it seems to become pretty constant once you pass the number of cores on the machine. Also keep in mind that this benchmark is completely unrealistic. No one is writing busy loops that just yield as quickly as possible outside of microbenchmarks.
This benchmark was run on an AMD 2700X, so, 8 physical cores and 16 logical cores.
comment 8y ago · link · parent
The point I'm trying to make is that you can't share resources easily between all of those processes, even though they're on a single machine, so you usually open a lot more database connections that you would need with a single shared connection pool. So, people often end up dealing with PgBouncer and other inconveniences much earlier than they would otherwise need.
But you're right, it's not necessarily forking.
comment 8y ago · link · parent
Fibers are cooperative here, but not from the programmer's point of view, and that's an important distinction to make. If you write the same code for a cooperative system as you would for a preemptive system, is there really any difference to the programmer? It looks preemptive. If anything, properly implemented cooperative systems are more efficient. Most of the time when people ask the question that is asked higher in the thread, I believe they're worried that they will be responsible for remembering to yield control.
I'm pretty sure I did a decent job in my previous comment of explaining that the system only looks preemptive, and that it is possible to block it with some uncooperative code, so I'm not sure what point you're trying to make.
comment 8y ago · link · parent
if I remember correctly, Go's scheduler has a global queue and a local queue per worker thread, so when you spawn a goroutine it probably has to acquire a write lock on the global queue.
Allocating a brand new goroutine stack and doing some other setup tasks has a nontrivial overhead that has nothing to do with context switching, regardless of global locks.
To properly benchmark this, I think I would start with just measuring single task switching by measuring how long it takes main to call https://golang.org/pkg/runtime/#Gosched in a loop a million times. This would measure how quickly Go can yield a thread to the scheduler and have it be resumed, although this includes the overhead of calling a function.
Then I would launch a goroutine per core doing this yield loop and see how many switches per second they did in total, and then launch several per core, just to ensure that the number hasn't changed much from the goroutine per core measurement.
Since Go's scheduler is not bound to a single core, it should scale pretty well with core count.
I might run this benchmark myself in awhile, if I find time.
comment 8y ago · link · parent
Any time you call a blocking function that the system provides, it should immediately yield the fiber, which makes it look preemptive. If you write a loop that just spins forever, that could block the whole system, potentially, making the abstraction leaky. In a language like Ruby, they could definitely add some true preemption, but I don't know if that's what they plan to do.
From the article: "Fibers, on the other hand, are semantically similarly to threads (excepting parallelism), but with less overhead." So, the author definitely isn't implying parallelism of the fibers.
> What's all the fuss about paralllelism in the article about then?
The author was talking about different methods for handling more than one request at a given time, which include forking and threads. With Ruby's GIL, threads are a lot less attractive than they could be. A good fiber implementation can handle tons of network requests concurrently and very efficiently even on a single core, which is the case being discussed here.
At the end, the author discusses a hybrid approach of forking and fibers, where each processor core would have a fork of the Ruby program running, and each fork would have its own fiber pool, running many tasks concurrently.
In languages that don't have a GIL, forking is rarely a tool that I reach for. It really hurts your database pooling and all sorts of other small problems, but it's a common trade-off when using Ruby, Python, and Node.
comment 8y ago · link · parent
On a 3GHz (3 billion hertz) processor, you expect to be able to context switch billions of times per second?
I would probably accept millions without question, even though that might be pushing it for a GIL-ed runtime like Ruby has. But, unless your definition of "context switch" counts every blocked fiber that's passed over for a context switch as being implicitly context switched to and away from in the act of ignoring it, I find this hard to believe.
It takes more than one clock cycle to determine the next task that we're going to resume execution for and then actually resume it.
comment 8y ago · link · parent
If accurate, this is a significant functional difference as far as I'm concerned.
But, what's the old saying again? "The only truly secure system is one that is powered off, cast in a block of concrete and sealed in a lead-lined room with armed guards - and even then I have my doubts."
comment 8y ago · link · parent
The Phoronix benchmarks are quite clear,[0] I don't know why you keep linking to AnandTech's Windows benchmarks. I say this as someone who reads tons of AnandTech reviews because they're great, but Windows just doesn't do well with high core count hardware at all.
[0]: https://www.phoronix.com/scan.php?page=article&item=2990wx-l...
comment 8y ago · link · parent
comment 8y ago · link · parent
For the record, those kids do not look like 5 year olds. Once someone is old enough to do abstract reasoning, I think Haskell might be a workable choice, if carefully taught. More often than not, it's more likely to drive them away than something simpler. That article appears to be using some web interface which was designed to hide all of the monads... I think that's a splendid way to get started. The students aren't writing their "main" function. Unfortunately, the website linked from that website is down, so it's hard for me to verify.
You haven't been listening to anything I have said, so I'm going to stop. I wish you would reflect on software education, because however well-intentioned, starting with Haskell is likely to drive many more people away than it would help to show what they can accomplish and inspire them.
comment 8y ago · link · parent
That "actual code" I mentioned can involve drawing on the screen, which as I pointed out in painstaking detail, is not going to be explainable to a five year old with Haskell code. That kind of visual feedback is incredibly important to concrete learners, which everyone is at that age.
Haskell and Python are not similar with regards to "conceptual/semantic complexity." At all.
I have used Haskell in the past. I understand it. Someone who hasn't reached Piaget's "formal operational" stage is not going to understand it. Piaget's theory isn't perfect, but it is normally true that people start out at a very concrete level.
As I said, don't be ridiculous.
Here is some super complicated Python code that kids can learn a lot from:
from turtle import *
color('blue')
forward(200)
left(90)
forward(200)
left(90)
forward(200)
left(90)
forward(200)
left(90)
done()
Eventually, they'll move on to using for loops! Or even asking the user a question and drawing something based on that. You literally have to understand (at a basic level) monads and effect systems to start implementing a question-response system in Haskell.Please, show me what my above code looks like in Haskell, since it's so comparable in complexity.
I don't think you have an appreciation for what goes into learning programming. You've probably been doing it for far too long at this point, without thinking back to the early days.
Why are you so defensive about Haskell in the first place?
comment 8y ago · link · parent
But more seriously, I strongly disagree about Haskell being anything like Python is for kids.
The level of abstract reasoning that Haskell requires for more than just adding two numbers is not easy or intuitive for kids. Following step-by-step instructions is intuitive. Writing Python line-by-line is easy to understand by analogy to a list of instructions. Eventually they can start using functions when they're comfortable, but you're very unlikely to succeed in teaching a five year old about typeclasses, monads, functional purity, effect systems, or anything like that. The thing with Haskell is that you have have to know almost all of that to do anything useful from day one. Even something as simple as drawing lines on the screen.[1]
Don't be ridiculous by suggesting Haskell is just the same to five year olds as Python.
[0]: https://wiki.haskell.org/Zygohistomorphic_prepromorphisms
comment 8y ago · link · parent
Attempting to arbitrarily differentiate between unreviewed code that you're writing and running versus unreviewed code someone else wrote that you're running would be a strange line to draw in the sand.
If they somehow decide to provide Xcode but don't provide a terminal at all, that would obviously be very limiting.
comment 8y ago · link · parent
I think that's kind of the point. Apple is going to eventually have to give certain classes of users more freedom if they want to see the iPad Pro adopted as a Pro platform.
Consistently, every single major review I read or watched for the iPad Pro berated Apple about this. The Verge, Engadget, MKBHD, and many others. Reviewers are not just letting Apple get away with this. Apple is going to have to open this up, even though some people like to believe they're never going to do that for some reason.
> most developers demand multiple monitors as well as the precision of a keyboard and mouse
iOS already has great keyboard support, and with the USB-C port on the iPad Pro, you can literally plug it into a USB-C dock and instantly have an external monitor, keyboard, and more connected, and yes, the monitor can show different content, it doesn't have to mirror the internal iPad display.
The iPad Pro's keyboard folio case is really great. I think it's actually a slightly more pleasant typing experience than what Apple's current generation Butterfly keyboards offer on their laptops.
Mouse support is another thing that reviewers have harped on Apple for. Whether they will support that at an OS-level or not is honestly more questionable than whether they're going to open up the underlying file system to advanced users, in my opinion.
> who would be the audience for XCode-on-iOS?
- Developers who like portability.
- Developers who like powerful hardware. (considering the iPad Pro is easily more powerful than the new MacBook Air and many of the MacBook Pros)
- Developers who like a great display... that 120Hz Liquid Retina display is really fantastic.
- Developers who enjoy long battery life.
- iOS Developers who want to save money. (an iPad Pro is cheaper than a MacBook, although not by as much as it should be)
Which developers wouldn't be interested in a professional-grade iPad Pro, given the list above? Unfortunately, Apple hasn't released such an iPad Pro yet, due to software limitations.
comment 8y ago · link · parent
The iPad Pro hardware is incredible, and if you're remoted into another computer, you're not really using the iPad Pro's hardware.
Regardless, for non-developer tasks, I think it would be really fun to have an iPad Pro. I just wish Apple would allow it to actually be a pro-level machine for developers. Apple is the limiting factor there.
comment 8y ago · link · parent
Maybe 4x is your cut-off point for where it's worth it to upgrade?
comment 8y ago · link · parent
I also feel like Microsoft and Apple are both doing cool stuff with the ARM space... but it would be cooler together. The iPad Pro is incredible, but iOS is so limiting. Windows 10 on ARM seems nice, but none of the hardware seems compelling, and no one makes a mobile ARM chip that's even remotely competitive with the A12X.
Since Apple is never going to let Windows 10 run on their iPad Pro, the least they could do is bring Xcode, Terminal, and external storage support to iPad Pro... but who knows if that's going to ever happen.
comment 8y ago · link · parent
I found a video of someone debugging Go code in VS Code, and I saw them set breakpoints, step around in a function, and hover over a variable to see its value, in addition to the sidebar containing all of the values of all of the local variables and the stack traces.
comment 8y ago · link · parent
It would be nice if someone wrote an article that did a deep dive on the current state of both of them.
Looking at Git activity, I can clearly see that Gitea is more actively under development by every metric.
However, since they are now divergent code bases, what does Gogs offer that would make someone inclined to use it over Gitea?
comment 8y ago · link · parent
If one of the best kept secrets of open source is that some BSD somewhere has great hardware support and battery life better than Windows and Linux... that would be awesome!
comment 8y ago · link · parent
[0]: https://gitea.io/