I want to re-write an app with large amount of concurrent users. Imagine a chat app that has millions of users connected via Websocket
. Used to I fine tune Python
Django
UWSGI
and an architecture that worked by today. Now I see slow connections and timeouts and so on.
I decided to use Go
language and drop Python and my question is that I couldn't find anything like UWSGI and I know Go has builtin concurrent capabilities. This means a Go server don't need something like UWSGI and can handle concurrent requests? or concurrency mentioned in go is just about simple I/O?
I need performance and concurrency in it maximum. I understand this issue well? These two are equivalent? Go can help me? and we don't need something like UWSGI and Go's core capabilities can work much faster and better in this issue?
CodePudding user response:
You should have a look at Go channels. Go channels in combination with Go routines can easily scale concurrency within the same process. Compared to Java Threading, Go routines are very efficient and have less context switching. Only 4kb mem consumption. In Go you don't share memory, but instead communicate state by pushing them on the channels, which results in no context switching to access shared memory.
Channels in Go work in a similar fashion as you would use some queuing system like Apache Kafka or RabbitMq.
I wrote an extensive example on this in following blogpost.
https://marcofranssen.nl/concurrency-in-go
If you are really new to go I can also advice to have a look at my other articles.
https://marcofranssen.nl/categories/golang
Read them from old to new to get familiar with the language after doing the quick start tutorial.
Once you know about Go channels you know how to efficiently implement the internal logic. For the external facing API I would choose https://grpc.io/ which allows to communicate on the TCP level. It allows to do streaming implementations in both directions.