amqp--php--example's Introduction
Hi Teamlead, The meaning of the solution: 1. All POST requests create an event in the data bus only. 2. Updating the data in the database is done with the help of the consumer. 3. Recording to the database occurs after processing several messages from the queue. Thus, a record in the database will occur only once every few seconds. 4. GET request takes data from the memcache. 5. A separate task writes the data to the memcache every few seconds. 6. The table with statistics has a partiton, the partition can be done by years, months or another period. 7. To determine the 5 most popular countries, there is a separate table with global statistics. 8. This table is updated by the consumer, but it can also sometimes be updated by the query to the main log table. 9. Also I can archive old records to reduce the log table. In doing so, I will take into account the archived data in the table to determine the top of countries. HTTP API: 1. POST `web/post.php` BODY like: `{"country": "RU", "event": "play"}` 2. GET `web/get.php?format=csv` 3. GET `web/get.php?format=json` (json by default) How to run: 1. `php consumer/calc.php` – main consumer 2. `php commands/requester.php` – just to create test data. 3. `php/cacher.php` – It should be run every few seconds to update the GET metod's cache. Due to the fact that the main requirement is performance, I left the code in a very simple version. Of course, I can make settings in separate files, that would not duplicate them, but I think the meaning of the task is not in this. Mysql DDL: create table statistic_global ( country varchar(3) not null primary key, count bigint default '0' null, constraint statistic_countrty_uindex unique (country) ); create table log ( date date not null, country varchar(3) not null, event varchar(10) not null, count bigint default '0' null, constraint log_date_country_event_pk unique (date, country, event) ); ALTER TABLE log PARTITION BY RANGE (YEAR(date)) ( PARTITION log2014 VALUES LESS THAN (2015) , PARTITION log2015 VALUES LESS THAN (2016) , PARTITION log2016 VALUES LESS THAN (2017) , PARTITION log2017 VALUES LESS THAN (2018) ); Original task: T3JpZ2luYWwgdGFzazoNCg0KSW1hZ2luZSB0aGF0IHlvdSBoYXZlIGFuIGFwcGxpY2F0aW9uIHdpdGggbWlsbGlvbnMgb2YgdXNlcnMuIFBlcmZvcm1hbmNlIGlzIGtleS4NCllvdSBuZWVkIHRvIGNyZWF0ZSBhIGJhY2tlbmQgZm9yIGl0IHdoaWNoIHdpbGwgaGFuZGxlIHRoZSBmb2xsb3dpbmcgdHdvIHJlcXVlc3RzLg0KVGhlIGJhY2tlbmQgaGFz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b3RlczoNCg0KVXNlIG9ubHkgcHVyZSBQSFAuIERvIG5vdCB1c2UgYW55IGZyYW1ld29yaw0KVGhlIHRhYmxlIHdpbGwgZXZlbnR1YWxseSBob2xkIG1pbGxpb25zIG9mIHJvd3MgYW5kIHRoZSBhcGkgd2lsbCBnZXQgZG96ZW5zIG9mIHJlcXVlc3RzIHBlciBzZWNvbmQuIFJldHVybmluZyAxMDAlIHVwMmRhdGUgaW5mb3JtYXRpb24gaW4gcmVzcG9uc2VzIGlzIG5vdCBhIHJlcXVpcmVtZW50IGJ1dCBmYXN0IHJlc3BvbnNlcyBhcmUu
amqp--php--example's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.