101 points by confusedgo_engineer 7 months ago flag hide 17 comments
user1 7 months ago next
I'm struggling to optimize my Go code for a distributed system. Any tips or resources?
go_expert 7 months ago next
Make sure you're using goroutines and channels effectively. The Go blog has a great post on this: https://blog.golang.org/concurrency-patterns
user1 7 months ago next
@go_expert I've read the post, but still struggling to see how to apply it to my specific use case.
another_user 7 months ago prev next
@go_expert Thanks for the link! I've never used pprof before, gonna try it now
optimization_guru 7 months ago prev next
Profile your code with the pprof tool, it will help you identify the bottlenecks: https://golang.org/pkg/net/http/pprof/
user1 7 months ago next
@optimization_guru I'll try that, thanks for the suggestion! Any other tips?
newbie_programmer 7 months ago prev next
Can someone explain what are goroutines and channels?
helpful_hn_user 7 months ago next
Goroutines are functions that run concurrently and channels are used to communicate between them: https://gobyexample.com/goroutines
helpful_hn_user2 7 months ago prev next
Here's a good tutorial on how to use them effectively in a distributed system: https://www.ardanlabs.com/blog/2019/03/concurrency-patterns-2-working-in-partnership.html
o_0 7 months ago prev next
Have you considered using message queues or a distributed cache like Redis?
user1 7 months ago next
@o_0 I have, but I'm not sure which one is the best fit for my use case. Any recommendations?
redis_fan 7 months ago next
Redis is a great choice for caching, and it also has built-in support for pub/sub if you need message queueing.
user1 7 months ago next
@redis_fan I'll take a look at Redis as well, thanks for the suggestion!
experienced_dev 7 months ago prev next
It depends on your specific requirements, but both RabbitMQ and Apache Kafka are popular choices for message queues.
o_0 7 months ago next
@experienced_dev Thanks for the recommendations! I'll take a look at them.
go_for_distributed_systems 7 months ago prev next
I highly recommend the GoConcurrencyPatterns forum for resources and discussions on Go and distributed systems: https://groups.google.com/forum/#!forum/goconcurrencypatterns
user1 7 months ago next
@go_for_distributed_systems Thanks for the link, I'll check it out!