Einführung
I work in a company where we run many batch jobs processing millions of records of data each day and I've been thinking recently about all the machines that sit around each and every day doing nothing for several hours. Wouldn't it be good if we could use those machines to bolster the processing power of our systems? In this set of articles I'm going to look at the potential benefits of employing an office grid using virtualised environments.
In Part 1 I gave an overview of the system and technologies I will be using as well as discussed some of the potential reasons why you would want to create an office grid.
Job Control
If you're going to be running jobs then you're going to need some way to manage them. Your job control system (on your job server) needs to be really well thought out before even attempting to run an office grid. So firstly, what are the tasks for a job control system:
- Hand out jobs upon request from workers
- Tell workers what type of jobs to run
- Track jobs
- Ensure that jobs are only run once
- Provide job data to workers, or at least tell them where to get it
The system also needs to be extensible, a solution that works for now in a single case may be extended to run several types of jobs as the business sees the worth in a grid solution. For example, jobs may gain priorities, more than one job type may exist (ie several code bases), eventually you may even run several different worker machines that are optimised for each type of job (although that does move away from the 'generic worker' idea). Always try to think about the future when developing systems, a short term vision can lead to longer term frustration and increased development time.
Job Server
We're going to need somewhere to control our jobs from, this should be the only system in your grid that has a fixed resource locator, be that an IP address, host name, URL (using internal DNS), etc. This is because the workers need to know where to look for jobs, workers need to find the job control system (not the job control system find the workers).
The job server itself doesn't really have a complicated task (in a basic system anyhow), it needs to store a list of jobs, hand out jobs, receive results, and subsequently store them for later retrieval. How these parts (such as 'hand out jobs') are defined can be very basic. Later on we can extend the system to include an administration interface to add, edit, delete, suspend jobs but this is beyond this exercise.
There is no reason whatsoever then that your job server could not be a virtual machine running within your main processing server provided it doesn't drain too many resources from it. The job server however does need high availability, if it goes down on a Friday evening you're going to lose a whole weekend of processing, potentially costing you a couple of weeks worth of processing time (when compared to your main processing server alone). You may want to consider putting your job server on a load balanced environment for high availability.
Basic Setup
Die Grundeinstellung für unseren Job Server wird von dem, was ich rufe einen meiner LIMP-Server (das ist Li nux, m ySql, P HP) bestehen. Der Code, der auf Thea Arbeiter tatsächlich herausfinden, was Arbeitsplätze es laufen kann durch die Interaktion mit mit Job-Control-System-Datenbanken. Später konnten wir einen Web-Service und tatsächlich Hand Arbeitsplätze, anstatt die Arbeiter nicht die harte Arbeit selbst zu erstellen, aber jetzt werden wir weiterhin mit dem KISS-Prinzip (Keep it simple, stupid!).
So können Sie drei mySQL -Tabellen mit Arbeitsplätzen beschäftigen. Diese wird `Arbeitsplätze`, `jobRecords` und `jobResults` werden.
Hier verwende ich SQL Buddy eine großartige kleine Alternative zu phpMyAdmin , nur weil die leichter auf CentOS installieren (für die anderen sehen: 10 Great Alternativen zu phpMyAdmin )
Diese Tabelle besteht aus 5 einfachen Feldern,
- ID: Eindeutige Identifizierung der den Job
- Name: Könnte eine Kundennummer oder eine beliebige Anzahl von anderen Kennungen werden
- Status: Sie müssen wissen, wo die Arbeit ist, z. B.
- 0: Nicht gestartet
- 1: Nahm
- 2: Abgeschlossene
- started_by: Wer angefangen hat, den Job? Dies ist nicht ganz erforderlich, aber ein nice to have. Ich würde Tracking Arbeiter durch ihre IP-Adresse in Ihrem Netzwerk vorschlagen
- started_at: Wann hat der Arbeitnehmer Beginn der Arbeit? Durch die Verfolgung Jobs, die nicht innerhalb von X Höhe der Zeit, dass wir wissen, müssen wir holen den Job noch einmal und starten Sie die Verarbeitung durch einen anderen Arbeitnehmer abgeschlossen haben. Workers könnte Stop Verarbeitung / go für eine beliebige Anzahl von Gründen, Stromausfall, Absturz-, Netzwerk-Verlust, etc. offline
Es ist leicht, wie diese Tabelle mit ein paar zusätzliche Felder ausgedehnt werden könnte, um für die Statistik-Tracking, ein Endzeit-Spalte, um zu sehen, wie lange der Job annahm, einen Zähler, um zu sehen, um zu neigen, wie viele Arbeiter nahm den Job (natürlich muss dies erlauben 1), Job-Priorität, kann die Liste weiter und weiter gehen. In more complex job scenarios it would be possible to specify how much memory the worker would need access to (and therefore only use suitable workers), or even what type of worker would be required.
Lets add a few example jobs:
The next table again is quite simple to understand, these are our job records. They are linked to the main jobs table by a column `jobs_id`. The make up of this table very much depends on the data that you need to supply to your workers, lets make a very simple example where we have four columns:
- id: ID of the record
- name: Person's name
- address: Person's address
- jobs_id: The job ID that this record is linked to
The third and final table consists of a results table, it has much the same make up as our records table, and with the addition of some columns could be part of the records table:
- job_record_id: Link the result to the job table
- result: The result data
…and that's all you need for job control! (albeit at a very basic level) In my case I'm pointed to another table where my data to process was located, but this could just as easily been a file, parameters to run simulation code, you name it.
Selecting a job
Wie bereits erwähnt, werden die Arbeiter unserer Job-Management für uns tun jetzt, so alles, was wir brauchen, um wirklich zu tun ist einen Job zu finden, dass die Verarbeitung braucht und die Informationen. Wie würden wir das tun? Nun holen unsere Aufgabe Auswahlkriterien und suchen Arbeit, in SQL Ich habe die folgenden:
- Nehmen Sie alle Jobs, die nicht so vollständig, aber aus unserer Arbeiter sind markiert und zurückgesetzt werden (Ersatz __ME__ mit einer Kennung, am einfachsten wäre IP-Adresse):
UPDATE `Arbeitsplätze` SET `status` = 0 WHERE `status` = 1 AND `started_by` = __ME__;
- Mit unserem Job Auswahlkriterien, wählen Sie einen Job und sagen, die Regelung, dass diese Arbeitnehmer mit ihm zu tun haben:
UPDATE `Arbeitsplätze` `status` = 1, `started_by` = __ME__, `started_at` = NOW () WHERE `status` = 0 oder SET
(`Status` = 1 AND `started_at`> DATE_SUB (NOW (), INTERVAL X HOUR)) ORDER BY `id` ASC;
Durch grabbing Jobs, die nicht Ergebnisse wurden in X viel Zeit wir dafür sorgen, dass alle Arbeitsplätze im Falle eines Arbeitnehmers Abstürzen oder gehen AWOL ausgeführt werden zurückgegeben.
- Als nächstes hol dir die Jobs Details durch die Datensätze selbst verfolgt:
SELECT * FROM `Arbeitsplätze` WHERE `started_by` = __ME__ LIMIT 1;
SELECT * FROM `job_records` WHERE `id` = __JOBID__;
Nach Abschluss der Arbeit setzen wir unser Ergebnis Aufzeichnungen und markieren Sie die Aufgabe als abgeschlossen. Denken Sie daran, wie Arbeitsplätze können suspend / jederzeit wieder aufnehmen können für einige Robustheit in Ihrem Skript. Es könnte sein, dass die Aufgabe auf halbem Weg unterbricht durch die Aktualisierung der Job-Steuerung, so überprüft die Anzahl der Datensätze in einem Job und die Anzahl der Ergebnisse zurück an den Job-Steuerung gespeichert wäre eine weise Entscheidung.
Darüber hinaus, während dies zeigt, wie Arbeitsplätze ausgewählt werden kann und aus einer SQL-Abfrage Rahmen wirklich verwaltet werden sollte, zu abstrahieren Ihre Arbeit kontrollieren, so dass, wenn Sie sich entschließen, die Verwendung eines Web-Service, eine Datei-basierte System, schalten XML , oder jede andere Anzahl der Systeme wird es keinen Einfluss auf die Code darüber.
Job-Konfiguration
Der nächste Aspekt ist die Größe des Auftrags und Konfiguration. Durch das Spiel mit Job-Konfiguration können wir schlagen eine exzellente Balance zwischen Geschwindigkeit, Prozess-Replikation und Zuverlässigkeit. Nehmen Sie ein paar ofa Szenarien:
- Jobs nehmen jeweils 1 Tag zu laufen: Dies bedeutet, dass Ihre Mitarbeiter 15 Tage brauchen, um jeden Job Prozess (Sie erinnern sich 10% der Energie für 2/3rds der Zeit). Dies ist offensichtlich nicht eine weise Konfiguration ist es Ihre Aufgabe Größe viel zu groß! Es würde mindestens die doppelte Zeit, um einen Job verarbeitet bekommen die ersten Arbeiter gehen sollte AWOL (Zeit abholen, dass es nicht wieder ein Ergebnis sowie Wiederaufbereitung Zeit). In einer idealen müssten Sie mindestens einen vollen Job einfach bis zum Ende des jeweils langen Ruhezeit geräumt, da man so die Arbeitsplätze Leerlauf und im schlimmsten Fall ein Job behalten würde zwei Tage dauern die ersten gehen sollte fehlen.
- Jobs nehmen 1 Minute zu laufen: Dies bedeutet, dass Ihre Mitarbeiter etwa 15 Minuten dauern, bis jeder Auftrag ausgeführt. Dies mag zunächst scheinen ideal, Ihnen zusätzliche Arbeit Verarbeitungsverstärkung während der Mittagspause, Kaffeepausen, Meetings, etc diesem Szenario belastet die andere Bereiche Ihres Systems und stellt seine eigenen Probleme. Zum Beispiel, zunächst das Setup / Bearbeitungszeit Verhältnis wird sich bis hinunter zu gehen, daher verlieren Effizienz des Systems. Ihr Netzwerk sein wird ständig Streaming Job-Informationen zu den verschiedenen Arbeitern frustrierend Mitarbeiter, dong sind ihre tägliche Arbeit. Sie werden auch mehr Belastung für Ihr Job-Verarbeitung-Server setzen, wie es austeilen viele, viele kleine Stücke von der Arbeit auf einer regelmäßigen Basis hat. Schließlich, in dieser Situation, wenn dein Job Server ausfällt wirst du eine riesige zurück Protokoll nicht abgeschlossener Arbeiten während größere Arbeitsplätze schaffen könnte Weiterverarbeitung völlig ahnungslos, dass der Job Server war in Schwierigkeiten.
In reality there will be no one ideal configuration for your grid setup, much depends on the available resources, types of job, job turnaround time requirements, network capability, and so on. However some guidelines would be:
- Size jobs so that each worker can get through at least 3-4 jobs in a period of 15 hours (the longest likely idle time period)
- Play with the job size so that setup time becomes fairly insignificant compared to the processing time (bearing in mind the above point).
- If a job doesn't complete in double the amount of time (maybe less) you expect it to complete it assume that its gone AWOL and start processing it with another worker. This means you may have to wait up to three times the normal length of a job for it to complete (possibly longer if the subsequent job fails). You may want to reduce this time, but be careful not to reduce it too much as you may start duplicating processing tasks on a regular basis.
- Jobs should be independent of outside requirements as much as possible. The job server, for example, should only be contacted at the start and end of every job.
- Don't saturate your network, this will have two negative effects, your daytime staff will find using the network frustrating and problems may be experienced with connections timing out a problem that will only get worse as you scale your grid.
- Ensure jobs can run on your workers. If jobs become too memory intensive or disk space intensive jobs will start aborting and the only thing you'll notice is a drop in number of jobs processed with no real reason why.
Submitting Results of a Job
When submitting the results of a job it is important to check that results have not been submitted by another worker, especially if the current worker has been dormant for some time.
When results are submitted ensure that the number of results matches the number of records within the job.
As stated previously, and can not be over emphasised, build fault tolerance into job retrieval and results submission. The workers can (and most likely will) go into suspend mode at the most inconvenient of times and this needs to be catered for. Also once again abstracting away your results submission will help cater for future changes to your job control system much easier to deal with.
Zusammenfassung
In this section we have looked at what a job control server needs to do and how to get a very basic system set up. We discussed how to retrieve a job from the control system and how best to configure jobs to get the most our of your office grid system. To finish, a paragraph or two on submitting results back to the job control server was presented.
- A job control server manages jobs and ensures that all work units are completed
- By abstracting your job select/results submission we can change the technology of the control server without much problems
- Configure your jobs to ensure that they are run quickly and efficiently without putting too much pressure on your network infrastructure, and without duplicating processing tasks on a regular basis.
- Ensure that you build fault tolerance and error checking into your routines, workers can suspend and resume and the most inconvenient of times. Remember to check if results have already been submitted by another worker.
Nächstes Mal
In part 3 we'll create our virtual processing machine and set up our windows machines to become idle-time workers.