Better HN
topnewbestaskshowjobs
Log inSign up

coder543

6,698 karma · joined Jul 18, 2012 (14y ago) · 1,967 submissions

My email is at gmail using my username.

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

Submissions

comment 8y ago · link · parent

In my experience, it's all handled transparently behind the scenes... there is no headache. In Rust, checking a connection out is a single function call on the pool, which is easily shared among all threads, and it will automatically get checked back into the pool when the connection goes out of scope... you don't have to do a single thing to check it back in. In Go, the connection pooling is all handled transparently behind the scenes, such that you don't even need to know it's happening. I actually had to do some googling when I started using Go, as I was concerned that no one was recommending the use of a connection pool... creating and tearing down a connection per request is just wasteful when connection pools are so nice to use. It just turns out that Go embraces connection pools so deeply that I don't know of an easy way to avoid pooling your database connections.

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

The one additional comment I have is that this addendum doesn't involve a reactor/scheduler in the benchmark, so it excludes the process of selecting the coroutine to switch into, which is a significant task. The Go benchmark I posted above is running within a scheduler.

But, I appreciate the addendum.

comment 8y ago · link · parent

I wrote my own quick benchmark: https://gist.github.com/coder543/8c1b9cdffdf09c19ef61322bd26...

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

ok, so that is a fair distinction.

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

I meant all kinds of internal forking. Running a process per core is just pre-forking.

comment 8y ago · link · parent

cooperative multitasking typically implies (to me, at least) that the programmer is required to explicitly / manually yield their task, which is annoying, error prone, and isn't required here. The system's blocking functions will handle that behind the scenes.

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

I don't think you're measuring context switching.

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

> So it is preemptively switching then?

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

Fibers are basically just async tasks where each task looks and feels like a normal, synchronous thread to the programmer.

It doesn't really imply anything about how parallel (or not) the fibers execute.

comment 8y ago · link · parent

> fibers can context switch billions of times per second on a modern processor.

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

Sources are conflicting, but the general consensus I've seen is that the Intel ME has direct access to your networking hardware, while the AMD PSP does not, and basically just exposes interfaces to the CPU.

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

AnandTech really needs to hire a Linux-focused editor to do some benchmarks there too, especially for these large systems that are unlikely to be running Windows anyways.

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

A10X or A12X? But there are a number of benchmarks showing the A12X outperforming most of Apple's laptop lineup and many competitors. The A12X doesn't have the liberty of a desktop form factor, so it is definitely a mobile part, but it seems reasonable that Apple could make another chip that scales the performance up even further if they wanted to, without really altering the underlying architecture.

comment 8y ago · link · parent

I never said Lisp nor Logo was a bad choice, now did I? Lisp is incredibly simple, even if it makes some things obtuse for beginners. I would rather have a strong type system like Haskell's for working on a large application, but Lisp is way easier to get started with. The parentheses are a huge stumbling point, though, which is where Logo comes in.

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

Unlike jolux's comment, I can agree with yours entirely. The tighter the feedback loop between code and graphical response, the more enticing it is to new learners. Scratch takes away the pain of trying to type picky syntax. It's a great starting point.

comment 8y ago · link · parent

My suggestion is that they won't write functions, not for quite awhile. Why would they ever need to understand decorators or object oriented design to start writing code!? They can write actual code though, not just addition in some REPL. In Haskell, you do need to understand a crazy number of things to do anything.

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

Zygohistomorphic prepromorphisms[0] are a common topic of discourse among five year olds, for sure...

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

[1]: https://docs.python.org/3.7/library/turtle.html

comment 8y ago · link · parent

I'm pretty sure a watt balance and a Kibble balance are the same thing. Regardless, that YouTube video is so good! I was just about to post the same link.

comment 8y ago · link · parent

If you're going to have a full IDE where you can write and compile code that Apple has never seen, it makes sense that developers would be able to download and run unsigned binaries inside the terminal for development purposes.

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

Quoting myself from the top of this comment chain:

> the least they could do is bring Xcode, Terminal, and external storage support to iPad Pro

I think a virtual terminal is a necessary piece here, which implies a Unix shell.

comment 8y ago · link · parent

> Can they really build an Xcode for iOS while sandboxing apps and refusing to expose the underlying file system?

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

At that point, why buy an iPad Pro to work at 5 FPS only when you have an internet connection, when you could buy a laptop that works at 60 FPS all the time?

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

Single core perf has become more than 50% better on desktop since Sandy Bridge, and it should be even more than that in TDP constrained environments like laptops because of reduced power consumption, which is partly why we now have quad core / eight thread ultrabooks. The total performance of such a device would almost certainly be more than double an X220 in a slimmer package.

Maybe 4x is your cut-off point for where it's worth it to upgrade?

comment 8y ago · link · parent

Is Visual Studio going to be available in an ARM native format? I understand you can emulate x86 applications on Windows On ARM, but it would be nice if they provided a native performance experience.

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 would like to think technology has advanced some since 1979.

comment 8y ago · link · parent

I personally almost never use a debugger with Go (or Rust), but it looks like you can get all of that functionality with VS Code using Delve: https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-cod...

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

There are a lot of conflicting opinions, even on that thread.

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

I agree that this can be beneficial, but do any BSDs support any laptop hardware as easily or as well as Linux does? Even assuming that hardware support is there, does the battery life even compare well to Linux on the same hardware, let alone Windows 10?

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

Gogs has been succeeded by Gitea[0], as I understand things.

[0]: https://gitea.io/

1
6263646566