📜 ⬆️ ⬇️

Click Count Server

If your project uses a count of clicks and there is a substantial load on it, then you probably thought about a separate solution.

The history of development goes into one project of the trade and advertising platform, where it was necessary to take into account the number of transitions. There was a decision on PHP. But it gave a visible delay of 0.5-1 sec, which is very annoying for developers (in particular, me) and I think the users, too.

Therefore, when I had to develop a similar project, I had to look for alternatives.
')
What happens when you click and account clicks:
- it is necessary to remove the transition url by one key
- write data to the log or database

Not finding industrial solutions there were two options:
- write a module for nginx;
- create your own solution;

We decided not to console nginx and created our own http server, to which requests through nginx are proxied. Although this server can act independently. Sources here

The decision is not industrial in nature, but so far proved to be quite reliable. It is being tested on a new project. During the installation, it will be necessary to correct the paths in the Makefile.

User-friendly configuration file. Most of the parameters can not touch. You must specify the host and port on which the server will sit.

The project uses the concept of inStorage and outStorage engine. They are defined by a single interface IStorage.cpp. This is a database (storage) for storing information.

Memcachedb is used as inStorage, in which data is stored: key / address
transition.
MongoDb is used as outStorage, in which logs are written. This functionality is optional, as access.log is maintained:
2010/10/08 11:38:30 127.0.0.1 GET /xxx?12345 404
2010/10/08 11:38:30 127.0.0.1 GET /leads?12345 200

You can write an extension (module) for any data warehouse using the IStorage interface. In this case, you need to change the lines in main.cpp IStorage * inStorage = reinterpret_cast<IStorage *>(new inputMcStorage);
IStorage * outStorage = reinterpret_cast<IStorage *>(new outputMongoStorage);
IStorage * inStorage = reinterpret_cast<IStorage *>(new inputMcStorage);
IStorage * outStorage = reinterpret_cast<IStorage *>(new outputMongoStorage);
on your class and rebuild the server.

At 404 error, you can set the address of the transition. see config.

In my project on click-server data is being proxy through nginx.

It should be noted that on a weak gland the server withstands 1200rpq, which is quite enough. Almost no delay is seen (1-3 ms). The memory consumed is 600K, so it does not require a separate iron.

I hope this decision will be useful not only for me.

Source: https://habr.com/ru/post/107713/


All Articles