Introduction
Hello!
In this article I will share my experience in building a microservice architecture for a project using neural networks.
Let's talk about architecture requirements, look at various structural diagrams, analyze each of the components of the finished architecture, and evaluate the technical metrics of the solution.
Enjoy reading!
A few words about the problem and its solution
The main idea is to assess a person's attractiveness on a ten-point scale based on a photo.
In this article, we will move away from describing both the neural networks used and the process of data preparation and training. However, in one of the following publications, we will definitely return to the analysis of the assessment pipeline at an in-depth level.
Now we will go through the evaluation pipeline at the top level, and will focus on the interaction of microservices in the context of the overall project architecture.
When working on the attractiveness assessment pipeline, the task was decomposed into the following components:
- Selecting faces in a photo
- Assessment of each person
- Render the result
MTCNN. PyTorch, backbone ResNet34 ā Ā« / CPUĀ»
ML , , .
ML
ā -, . :
- ā ,
- ā Bottleneck
- - ā
- () ,
- , ,
, .
, , Telegram API.
, , .
, Single Responsibility .
Ā«attrai-telegram-botĀ»
Telegram API. 2 ā . .
:
- , :
- ,
- docker volume
- āto_estimateā , , , , volume
- ā , . ā , .
, , celery worker, Ā«after_estimateĀ», , .
āafter_estimateā:
- ā , ā
- ,
Ā«attrai-estimatorĀ»
celery worker , . ā .
āto_estimateā:
- :
- (MTCNN)
- ( ResNet34)
-
- bounding boxes
- ()
- āafter_estimateā, āattrai-telegram-botā
Graylog (+ mongoDB + Elasticsearch)
Graylog ā . , .
, ELK , Python. , Graylog, GELFTCPHandler graypy root logger handlers python-.
, , ELK , , Graylog. , ā Kibana - Graylog.
RabbitMQ
RabbitMQ ā AMQP.
Redis
Redis ā NoSQL , Ā« ā Ā»
python- , - .
, Redis hashmap Ā«telegram_user_id => Ā», , , DoS-.
- Telegram
- Ā«attrai-telegram-botĀ» Telegram API
- Ā«to_estimateĀ»
- Ā«attrai-estimatorĀ» Ā«to_estimateĀ», Ā«after_estimateĀ»
- Ā«attrai-telegram-botĀ», Ā«after_estimateĀ»,
DevOps
, , ā DevOps
Docker Swarm
Docker Swarm - , Docker Engine .
Ā«Ā», 2 ā worker manager. (), , . .
leader manager worker
ā 1 , leader manager worker. , .
, , production-, , , , ( , - - , ).
Docker Stack
Ā«Ā» ( docker services) docker stack
docker-compose , deploy .
, ( N N , - , PyTorch`, )
attrai_estimator:
image: 'erqups/attrai_estimator:1.2'
deploy:
replicas: 4
resources:
limits:
cpus: '4'
restart_policy:
condition: on-failure
ā¦
, Redis, RabbitMQ Graylog ā stateful , Ā«attrai-estimatorĀ»,
ā Kubernetes?
, Kubernetes ā , Docker Swarm, user friendly , .
VDS :
- CPU: 4 IntelĀ® XeonĀ® Gold 5120 CPU @ 2.20GHz
- RAM: 8 GB
- SSD: 160 GB
, , , .
, , (, ), . CPU RAM .
, ,
, , ā .
, , CPU, , .
I will add that initially the article was larger, but in order not to post a longread, I decided to omit some points in this article - we will return to them in future publications.
You can poke the bot in Telegram - @AttraiBot, it will work at least until the end of autumn 2020. Let me remind you - no user data is stored - neither the original images, nor the results of the evaluation pipeline - everything is demolished after processing.