A
A
Alexey Solodky2013-03-25 20:43:12
linux
Alexey Solodky, 2013-03-25 20:43:12

What is the best way to write a big demon?

The task is to write a large complex system that will work stably in the background for a long time.
I myself specialize in PHP, but I understand that it is not very suitable for this task.
What do you advise? Ruby, python, framework or pure.
I would like to have a convenient work with the database (ORM?), http.
Thank you.

Answer the question

In order to leave comments, you need to log in

15 answer(s)
G
giner, 2013-03-25
@DoctorX

A little story.
- He wrote his first demon in Python (it was python 2.6 or 2.7, I don’t remember already). I worked but ate a lot of memory, and over time I ate more and more. Out of love.
Then I started writing perl. Everything was fine as long as the daemon had to run on Linux. When it was necessary to transfer to Windows, problems were discovered (forks were born, but not killed), which could not be solved. Perhaps perl relies heavily on the Linux architecture.
Then I decided to try ruby ​​and found a scripting heaven. The daemon, which was previously written in perl, was easily ported to ruby, and the code was reduced by half. Under Windows, I didn’t have to finish anything at all. Works the same everywhere.
- In the end, I decided for myself that if I write utility scripts, then both perl and bash will do, and if demons, then ruby.
I do not take into account performance, tk. has never been required, but ruby ​​excels in simplicity and portability.

K
kasthack, 2013-03-25
@kasthack

Real demons are written in Ada.

Z
Zerstoren, 2013-03-25
@Zerstoren

Author, I understand you. Once I had the imprudence to write a demon in PHP, which I regret. Although he worked stably, he harassed me.
Python is a wonderful language for such a task, those who write about memory leaks did not help the garbage collector much.
I'm writing a daemonic websocket server, with a thousand logins and logouts over several days, no leaks. As the code ate 7MB of RAM, so after disconnecting all users, it continued to eat 7MB of RAM. The differences were reduced to kilobytes.
If you decide to write in Python, then a couple of recommendations:
- For each iteration of data processing, create an instance of the class, which will include other subclasses that will carry out data processing. Don't store object references in modules or non-destructible classes. Classes must be destroyed after each iteration.
- Go closer to functional style. You gave data to some function, it returned a result.
Leave nothing unattended.

J
jetman, 2013-03-25
@jetman

Large and complex system? I will advertise the key features of Golang in relation to your case:
- static typing
- lightweight out-of-the-box streams
- extensive standard library
- built-in unit testing system
- easy to learn for PHP programmers
golang.org

T
TyShkan, 2013-03-26
@TyShkan

I recommend looking towards phpdaemon

A
afiskon, 2013-03-26
@afiskon

I think Perl or Erlang will suit you. Perl is very easy to learn after PHP, demons are easily written on it, there is a wonderful ORM (DBIx::Class). Erlang is great with immutable variables, functional style, multithreading, and automatic garbage collection. There is a wonderful web server (not a framework) Cowboy. True, with ORM it is not going smoothly, as well as with firewood for the DBMS (emysql has known unclosed bugs, epgsql has performance problems if there are a lot of requests). I once wrote about many of the above in my blog , you can search for it.

K
kamiram, 2013-03-25
@kamiram

python is quite convenient and popular for such tasks. but it should be noted that zhruch, for example, to memory.
demonu lupus est.
what a demon. there are different requirements.

L
lsf, 2013-03-25
@lsf

If I were you, I'd stick with PHP. Along the way, I would figure out what crontab is. If this is not enough for you, you will think about something else.

V
vsespb, 2013-03-25
@vsespb

Perl is great.

B
B7W, 2013-03-25
@B7W

If you need a serious large multi-threaded application, it is better to look towards java. The local library, and the virtual machine, are most suitable for such tasks.
Python, Ruby have GIL. And there are no serious tools for multithreading in them.
There is a GIL bypass in python - the multiprocessing package, if you look at it. ORM - SQLAlchemy, http - there is a base and other libraries.
In general, you need to look at tasks, otherwise php may be enough for you.

D
DrNemo, 2013-03-25
@DrNemo

first of all, it all depends on the tasks of the demon!
I will give an example: I have a daemon that collects a lot of statistics from my projects and controls their availability. projects under control are different, there are also moderately loaded ones.
so, the daemon is written in python and works on my old desktop based on intl celeron 1.7 with 2 gigabytes of RAM (DIMM
)
.

O
Ogoun Er, 2013-03-29
@Ogoun

C# is perfect, I make non-pageable applications on it, they work stably for months, memory does not leak.

S
sylord, 2013-03-26
@sylord

One big one is better not to do. And write several that perform different tasks. And then decide what to write on. Somewhere Bash is enough, somewhere you need (or faster) the same PHP. If you write correctly, nothing flows anywhere. It is also necessary to hang something like monit on the demon.

P
porzione, 2013-03-26
@porzione

We have already mentioned the requirements above, so it is important to know
1. Is memory consumption critical? whether it is necessary to keep within 50 mb, 100 mb, 200 mb?
2. Is it necessary to respond in parallel to several requests and is real multithreading needed?
If the answer to the second question is “yes”, then Erlang, for example.

P
plutov, 2015-02-01
@plutov

I write in PHP, it works stably, but I want to switch to Go plutov.by/post/php_daemons

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question