P
P
podlec2012-01-29 20:22:46
Python
podlec, 2012-01-29 20:22:46

Asynchronous Server: C or Python?

Hello, we need to make a server for a browser game, designed for high loads. Our client is in Flash. Expected online > 100k.
We want to make the server so that it effectively copes with the following tasks:
1) Asynchronously accept requests, save data in the database, send responses;
2) Data can arrive at the server in a large number, more precisely with a large frequency, perhaps even very large, so there is a need for a fast database;
3) The server must scale horizontally.

We are very hesitant about what to write it on. On the one hand, fast, but heavy in writing "C", on the other hand, simple and convenient Python. Since we have little experience with highly loaded systems, we cannot decide for ourselves with certainty what to do now, so as not to miscalculate later ...

Therefore, we would like to ask for help from habra people who may have had similar experience. We would like to know which language is better for us to stay in, which database is better to take, should we use any framework? We are very afraid of miscalculating, and articles on the network give even more questions than answers.

We would appreciate any advice or perhaps even personal experience.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

12 answer(s)
C
CKOPOBAPKuH, 2012-01-29
@podlec

If there is no experience, then with a 100% probability you will step on a rake, sit in a puddle and you will have to rewrite everything. If there was a highload experience, then the probability would be less, but still high.
It must be accepted as is. Whatever you do, if your project is doing well, then in terms of load, you will do a lot wrong.
Therefore, write in python, and when you write all the logic and set up the architecture, then calmly rewrite it in pros (yes. in pros. to write everything in C, it will take you much more time, so use the pros after all)

K
Konstantin, 2012-01-29
@Norraxx

I don’t know how much my experience will help you, but we solved a large load with three things:
1. nginx
2. several endless python processes (fastcgi + wsgi chain (flup)). (Processes can be not only on your server ;-))
3. MySQL table Memory. Once in a certain period of time, data is written to the tables on disk.
4. all the statics are not with us. (but we needed this to save traffic)

S
Sergey, 2012-01-29
@seriyPS

The joke is that asynchronous drivers are not made for most databases, so you either need to use a database with a simple text protocol and implement an asynchronous driver yourself at the socket level, or start threads for database connections and buffer data.
But in general, of course, it’s better to first write in python, conduct load tests and find out bottlenecks. Optimize Python code, perhaps rewrite part of it in C as a Python module.

A
Anatoly, 2012-01-29
@taliban

Iron in our time is cheaper than labor, so I would advise writing in python, as we wrote above, you can always rewrite the narrow part in the same C, and if everything is just so bad, just buy more iron. After all, the contact works on php, and he has much more than 100k online. So it's not about language, it's about skills.

A
Andrew, 2012-01-30
@Morfi

I think Erlang fits here.

A
a11aud, 2012-01-30
@a11aud

Monsieur alternativshik says business. Use tornado and radish. For simple queues in redis, read about the brpoplpush command , and for competent asynchrony on a tornado, read about how to write asynchronous code in a synchronous style . And you will be happy.

M
mentatxx, 2012-01-29
@mentatxx

I recommend reading www.kegel.com/c10k.html

K
kocherman, 2012-01-30
@kocherman

Last September I had the same question. I decided to use NodeJS.
Unfortunately, I can not confirm personal experience "like NodeJS with a load." But, comrades from America all unanimously only positive comments both in terms of simplicity and performance (that is, negative comments on the Internet in the direction of NodeJS, as a rule, are given by people who have not used it).

A
alternativshik, 2012-01-30
@alternativshik

Use a Facebook tornado in python, + a thread of radish to create queues or store key value data and quickly access it, the rest is optional.

S
Sergey Lerg, 2012-01-29
@Lerg

Mmm. I basically agree with the answer above about the rake. But you can use both C and Python - in C, implement only receiving / writing / sending data, and write logic in python. Twisted is not the fastest web framework out there.
For example, the client opens a permanent connection with the server (TCP or UDP is up to you (in the case of UDP, there is no permanent connection, of course)), gets to the balancer, it creates or selects a free process of a C program that receives data, writes to the database , notifies the Python script that the game state has changed, it in turn calculates the changes, generates data for sending and sends it to affected clients through the same C processes.
Programs can communicate either through shared memory or through udp sockets.

V
VBart, 2012-01-30
@VBart

uWSGI ;-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question