Trying to distribute data processing across a cluster and then aggregate it in master

蓝咒 提交于 2021-02-11 14:50:56

问题


Right now I have a Python Application which runs 50 threads to process data. It takes an xlsx file and will process a list of values, and will output a simple csv.

I said to myself, since this is a simple Python App with 50 threads, How can I create a cluster to distribute data-processing even more? FOR EXAMPLE: Have each Worker node process a subset given to it by the master. Well that sounds easy, just take the master app slice up the dataset generated and then push it to the workers with load balancing.

How do I get the results though? I would want to take all results (out.csv in this case) and return them to the master and merge them to create 1 master_out.csv

At first I was thinking a Docker swarm, but no one i know uses them, everything beyond a simple docker container is offloaded to K8.

Right now, i have a simple file structure:

app/
  __init__.py (everything is in this file)
  dataset.xlxs
  out.csv

I was thinking to create a docker image so that way I could move this app into the image, update/upgrade, install python3 if it isnt already, and then just run this application.

I started getting deeper into processing, and realized that there is likely some built in ways to handle this. create a flask app to handle ingestion, and then a flask app on master to accept files at completion, etc.... But then master needs to know all the workers etc.

  • I was thinking to create a cluster.
  • Master node has access to a volume which contains the file i need to process.
  • Load balancing pushes parts of each file ( ROWS / NUM_WORKERS) to each node.
  • After WORKERS FINISH, Master Aggregates the resulting csv files to make a master file.
  • Master_OUT.csv will exist in the folder for consumption.

So the cluster would turn on and when ready will run everything, then tare down at the end. Since they want the cluster to likely be distributed, I am not sure how that would work though as processing has IP Address limitations. It seems like this will not work on a local cluster because to machines being used to reference will hit a cloudflare (or similar) wall after enough requests, so im trying to think of a UNIQUE IP Solution.

I have an idea for architecture, but im not sure if i should create a dockerfile for this, and then figure out the way kube can handle all of this for me. Though i think in the kube config files we can put remote aws instance login creds so it will spin up all the remote servers.

While I have been doing some stuff with Swarms, It seems that kube is where the real work is done, as swarms seem to be better suited for other things.

Im trying to think of how I would approach this from a kube (or swarm) perspective.

Given the information, this concept reminds me less of load balancing because of the data aggregation and more of like Kubeflow, where you create a CLOUD specifically for ML, but instead of ML it would be ANY distributed processing.


回答1:


The interesting problems in this question have nothing to do with Docker; let's put that aside for now.

You expect you'll have a bunch of computers that are all processing a chunk of this big data set. You've already structured the problem so that you can do work on small pieces of the input and produce small pieces of the output. The main problems you need to design around are:

  1. Where do you keep the input so that the tasks can read it, if they need to?
  2. How do you pass on units of work to the workers? What happens if a worker fails?
  3. How do you communicate the outputs? Where do you store them? Do they need to be in the same order as the input?

A useful tool here is a work queue; RabbitMQ is a popular open-source implementation. You'd run this as a separate server, and workers can connect to it and read and write messages from queues. So long as everyone can contact the RabbitMQ server, none of the individual workers or other processes in the system actually need to know about each other.

For some scales of problem, a straightforward approach is to say the original input and final output is single files on a single system. You break this up into pieces that are small enough that they can fit in a message payload, and the responses also fit in message payloads. Run one process to read the input and populate the work queues; run some number of workers, and run a process to read back the outputs.

Input handler      +------+ --> worker --> +------+
dataset.xlsx  ---> +------+ --> worker --> +------+ --> Output handler
                   +------+ --> worker --> +------+     out.csv
                   +  ... +      ...       + ...  +

If you're using Python as an implementation language, also consider Celery as a framework to manage this.

To run this, you need to run three separate processes.

export RABBITMQ_HOST=localhost RABBITMQ_PORT=5672
./input_handler.py dataset.xlsx
./output_handler.py out.csv
./worker.py

You can run multiple workers; RabbitMQ will take care of ensuring that tasks get distributed across the workers, and that a task gets retried if a worker fails. There's no particular requirement that all of these run on the same host, so long as they can all reach the RabbitMQ broker.

If you can't keep the inputs or outputs in the message, you'll need some sort of shared storage that all of the nodes can reach. If you're in a cloud environment an object-store service like Amazon's S3 is a popular choice. In the input and output messages you would then put the path of the relevant file in S3 instead of the data.

How would Docker or Kubernetes fit into this picture? It's important to note that neither technology provides anything like a work queue, and shared filesystems can be spotty. Still, where I referred to the three different processes above, you could package those into three Docker images, and you could deploy those in Kubernetes. Where I said you don't have to run just one worker, a Kubernetes Deployment will let you run 5 or 10 or 50 identical copies of the worker, and RabbitMQ will take responsibility for making sure they all have work to do.



来源:https://stackoverflow.com/questions/60792927/trying-to-distribute-data-processing-across-a-cluster-and-then-aggregate-it-in-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!