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 ...
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 ...
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. ...
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 ...
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 ...
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 &...
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;
...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 {
...
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 ...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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 (...
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.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
golang × 42go × 13
unit-testing × 5
architecture × 4
testing × 3
design-patterns × 2
database × 2
rest × 2
api × 2
microservices × 2
interfaces × 2
multithreading × 2
concurrency × 2
postgres × 2
rust × 2
design × 1
object-oriented × 1
algorithms × 1
object-oriented-design × 1
programming-practices × 1
.net × 1
programming-languages × 1
licensing × 1
c × 1
git × 1