Skip to main content
181 votes

Does it ever make sense to use more concurrent processes than processor cores?

The canonical time when you use far, far more processes than cores is when your processes aren't CPU bound. If your processes are I/O bound (either disk or more likely network), then you can ...
Philip Kendall's user avatar
59 votes

Does it ever make sense to use more concurrent processes than processor cores?

Short answer: Yes. Longer answer: Set your magic number stupid high, benchmark it, set it low, benchmark it again, and keep doing that until you have your answer. The number of moving parts here is ...
Iron Gremlin's user avatar
  • 1,115
14 votes

Use of "this" in Golang

I am not convinced by this style guide and I don't think anything is better than this, me or self. Because this, me or self makes it super clear that the variable is an instance of the context struct. ...
Qian Chen's user avatar
  • 256
14 votes
Accepted

Making side effects explicit even in non-pure functions

A statement like s = s.IncreaseCount() can have the opposite effect of what you are trying to accomplish: it can give the reader the impression IncreaseCount does not mutate s by itself and ...
Doc Brown's user avatar
  • 214k
12 votes

Does it ever make sense to use more concurrent processes than processor cores?

In A.I. it is common for people to observe super-linear speedups when they write parallel algorithms (that is, > K times speedup with K processes running on K cores). This is because you are often ...
Chris Jefferson's user avatar
11 votes

Does it ever make sense to use more concurrent processes than processor cores?

You can take the example of compiled Linux distributions (like Gentoo): to optimize the compilation time, it is obviously using parallel compilation using more processes than the number of available &...
Philippe Verdy's user avatar
10 votes

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

"Composition over inheritance" for the Circle-Ellipse problem means to implement a class Circle by making internally use of an Ellipse object, like this: class Circle { Ellipse e; ...
Doc Brown's user avatar
  • 214k
9 votes

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

The circle vs ellipse problem (as well as the square vs rectangle) are not an inheritance problem but a problem regarding the contracts and promises made about the initial class. In the first place, ...
Christophe's user avatar
  • 80.6k
6 votes
Accepted

Go’s answer to c10k problem

There are two primary ways of dealing with socket connections, Blocking and Non-Blocking IO. Blocking IO typically allocates (at least) one thread to read from a socket, so that when activity occurs ...
DavidT's user avatar
  • 4,273
5 votes

Race conditions in API calls within Golang microservices

If you are using a distributed system, you get the drawbacks of distributed system: ensuring consistency of your data model requires real care. TL;DR: avoid distributed systems if consistency is ...
amon's user avatar
  • 135k
5 votes
Accepted

Is there existing technology write code to be executed in response to an email being sent for a certain email?

Common e-mail server software (postfix, sendmail, presumably exim but I didn't check that one) supports forwarding to programs via pipes, so this isn't esoteric at all. Ticketing systems such as ...
Hans-Martin Mosner's user avatar
5 votes

Does it ever make sense to use more concurrent processes than processor cores?

It depends. Mainly upon your workload and scheduler concept. Speaking precisely about Go, it is not just common, but absolutely right decision to spawn much more goroutines that you physical ability ...
Zazaeil's user avatar
  • 345
5 votes

Creating a new type as slice of strings in Rust?

Rust is broadly similar to how you would approach Golang, with the caveat that there are some quite relevant differences in the type system. For example: With Golang, you can create new methods for ...
amon's user avatar
  • 135k
4 votes

Why Golang projects seldom use mocking library in testing?

The approach that mostly used in test other than mock is fake --- fakes are merely structs that fit an interface and are a form of dependency injection where the consumers control the behavior. Some ...
lennon310's user avatar
  • 3,242
4 votes

Use of "this" in Golang

I have realized this only while reading the answers here: There is a real and significant difference between receiver in Go and this/self in most (all?) OOP languages: receiver is never polymorphic. ...
Frax's user avatar
  • 1,864
4 votes
Accepted

How to test interactors in clean architecture?

While writing interactors, I end up with a lot of complex unit tests, because the interactor has a lot of external dependencies. Really? The controller passes you a request model, you build a ...
candied_orange's user avatar
4 votes
Accepted

How to structure a Go application, architected according to the clean architecture

There are a few solutions to this: Package Separation Review Analysis Static Analysis Runtime Analysis Each having their pros/cons. Package Separation This is the easiest way that doesn't require ...
Egon's user avatar
  • 164
4 votes

design pattern to avoid deadlock with mutex in golang

There is no particularly good way, and Golang eschews abstractions that would make risky operations safer. Strategies you can consider: Prefer very fine-grained locks. Your code mostly does this, but ...
amon's user avatar
  • 135k
3 votes
Accepted

Cron job to read multiple "entities" from the database

The second option won't scale well... if that matters. Managing 1000 different schedules seems like a lot of work for me. Leave alone tracking and debugging if something goes wrong. Even if each user ...
Laiv's user avatar
  • 14.8k
2 votes

Does it ever make sense to use more concurrent processes than processor cores?

You ask for “any reason”. One reason would be that I don’t want to bother counting the number of available cores or virtual cores. And the number of available cores isn’t a good hint either, in case ...
gnasher729's user avatar
  • 47.5k
2 votes

How to test channel pipelines in Go

You are mixing two different concerns. If you made a separate abstraction for the pipeline, you could test that once. Something like (forgive syntax, I don't know go): func double(v int) int { ...
Karl Bielefeldt's user avatar
2 votes

How should I distribute my app with my own OAuth2 client ID, without letting anyone find it out?

Don't store your clientID on the client. Your app should store it's clientId and secret on the server. When a user signs into your app, they should begin an OAuth request through your server. Your ...
Michael Brown's user avatar
2 votes
Accepted

How to deal with licensing when importing remote packages in golang?

If you're not including the source code directly, you are not redistributing the code. However, you are using the library. So, you should follow what the library's licence says about usage.
Paul92's user avatar
  • 2,601
2 votes
Accepted

REST API with 1000 query templates?

Write 1000 packages. The benefit of doing it this way is that you make best use of your existing source control and deployment pipeline to manage the sql. Storing the queries somewhere else means ...
Ewan's user avatar
  • 79.9k
2 votes

Does it ever make sense to use more concurrent processes than processor cores?

Others have added great answers already, but I'd like to pitch in one more approach. Start by figuring out what your bottleneck is. That's done by profiling or just using common sense. Then optimize ...
Vilx-'s user avatar
  • 5,400
2 votes

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

If you have a class implementing an ellipse, then it is quite easy to create a class implementing a circle, which uses an ellipse internally to do all the hard work, and that ellipse would always have ...
gnasher729's user avatar
  • 47.5k
2 votes

Golang interface-implementation circular dependency

What is the reason behind putting the constructor in the interface and not in the implementation ? Your constructor returns an implementation not the interface, and interfaces should never be ...
f222's user avatar
  • 1,040
2 votes

How are interfaces implemented behind the scenes in the Go language?

In Swift, there are (kind of) objects that represent interfaces. Say an interface has three functions. Then the interface object has three function pointers and a bit of storage. When you pass an ...
gnasher729's user avatar
  • 47.5k
2 votes

Return function after kicking off background process

Define a manifest constant TIME_LIMIT=300 seconds which describes the duration within which you believe most successful copies will complete. some mechanism to check the status of the go routine (...
J_H's user avatar
  • 7,605
1 vote

Golang interface-implementation circular dependency

Comparing to Java, you should see that New() function as the constructor of your struct. And, like the constructor in Java, that function should be with the implementation, not with the interface. ...
Jory Geerts's user avatar
  • 1,606

Only top scored, non community-wiki answers of a minimum length are eligible