معرفی
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.
راه اندازی مقدماتی
The basic setup for our job server will consist of what I'm calling one of my LiMP servers (that is Li nux, m ySql, P HP). The code running on the workers will actually work out what jobs it can run by interacting with with job control system databases. Later on we could create a web service and actually hand out jobs rather than having the workers do the hard work themselves, but for now we'll continue using the KISS principle (Keep it Simple, Stupid!).
So, lets create three mySQL tables to deal with jobs. These will be `jobs`, `jobRecords`, and `jobResults`.
Here I'm using SQL Buddy a great little alternative to phpMyAdmin just because its easier to install on centOS (for others see: 10 Great alternatives to phpMyAdmin )
This table consists of 5 simple fields,
- id: Uniquely identify the job
- name: Could be a client reference, or any number of other identifiers
- Status: You need to know where the job is at, eg
- 0: Not started
- 1: Picked up
- 2: Completed
- started_by: Who's started doing the job? This isn't entirely required but is a nice to have. I'd suggest tracking workers by their IP address on your network
- started_at: When did the worker start the job? By tracking jobs that have not completed within X amount of time we know we need to pick up the job once again and start processing by another worker. Workers could stop processing/go offline for any number of reasons, power failure, crash, network loss, etc.
It is easy how this table could be extended with a few additional fields to allow for statistics tracking, a finish time column to see how long the job took, a counter to see how many workers picked up the job (obviously this needs to tend to 1), job priority, the list can go on and on. 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
همانطور که قبلا ، کارگران را مدیریت کار ما برای ما در حال حاضر برای انجام دهید ، بنابراین همه ما باید واقعا انجام دهیم این است که پیدا کردن یک شغل نیاز به پردازش و دریافت اطلاعات. چگونه این کار می کنیم؟ خوب کار ما انتخاب معیارهای انتخاب و به دنبال شغل ، در گذاشتن من به شرح زیر است :
- نگاهی هر شغل است که با عنوان کامل اما کارگر ما از علامت زده نشده است و تنظیم مجدد آنها (__ME__ جایگزین با شناسه و آسان خواهد بود آدرس آی پی) :
شغل تکمیلی `` `ست وضعیت` = `0 مکانی که در آن وضعیت` = 1 `و` = started_by __ME__ ؛
- ما با استفاده از معیارهای انتخاب شغل ، انتخاب شغل و به سیستم کنترل که که این کارگر است که برخورد با آن :
شغل تکمیلی `` `ست وضعیت` = 1 ، `started_by` = __ME__ ، `=` started_at همین حالا () مکانی که در آن وضعیت `` = 0 یا
(`وضعیت` = 1 `و` started_at> DATE_SUB (در حال حاضر () ، یک ساعت فاصله اکس)) سفارش شناسه `` صعودی ؛
با گرفتن کارهای که منجر به مقدار ایکس از هم اطمینان می دهیم که تمام کارها در این رویداد از یک کارگر که توفنده و یا رفتن AWOL اجرا برنگشت.
- بعدی گرفتن اطلاعات مشاغل و پس از آن سوابق خود :
* از انتخاب شغل `` `مکانی که در آن started_by` = __ME__ محدودیت 1 ؛
انتخاب * از job_records `` `مکانی که در آن شناسه` = __JOBID__ ؛
پس از اتمام کار ما قرار دادن سوابق نتیجه ما و مارک کار خود به عنوان کامل است. به یاد داشته باشید می توانید به عنوان شغل به حالت تعلیق / سر در هر زمان اجازه می دهد برای برخی از نیرومندی در اسکریپت شما. ممکن است که کار را متوقف نیمی از راه را از طریق به روز رسانی کار سیستم کنترل ، به طوری چک کردن تعداد رکورد را در شغل و تعداد نتایج بدست آمده به کار کنترل سیستم ذخیره می شود حرکت و حکیم است.
علاوه بر این ، در حالی که این نشان می دهد چگونه می تواند واقعا شغل انتخاب می شود و موفق گذاشتن - از پرس و جوی شما باید قاب چکیده کنترل کار خود را به طوری که اگر شما تصمیم به تغییر سیستم ، به یک وب سرویس با استفاده از پرونده ، بر اساس کاپرفیلد ، و یا دیگر تعدادی از سیستم های آن را به کد در بالای آن تاثیر نمی گذارد.
فرصت های شغلی پیکربندی
جنبه های بعدی در نظر گرفتن حجم کار و تنظیمات است. با بازی با تنظیمات کار ما می توانیم تعادل بین سرعت عالی ، پاسخگویی فرایند و قابلیت اطمینان اعتصاب. نگاهی به زن و شوهر of حالات :
- مشاغل را هر روز 1 برای اجرا : این به این معنی که کارگران شما نیاز به 15 روز تا روند هر شغل (به یاد داشته باشید 10 ٪ از قدرت برای 2/3rds از وقت). این به وضوح پیکربندی عاقلانه نیست ، اندازه شغل شما این است راه خیلی بزرگ! این امر را حداقل دو برابر این زمان را برای یک کار پردازش اولیه باید کارگر برو AWOL (هم انتخاب کنید تا به آن است که در نتیجه به علاوه زمان بازفرآوری بازگردانده نمی شود). در ایده آل شما می خواهم و حداقل یک شغل کامل تیک تاک به آسانی پاک در پایان هر دوره طولانی بیکار ، که راه شما را بیش از مشاغل در بدترین حالت یک کار طول می کشید ، دو روز به روند باید اول بروید گم شده است.
- مشاغل را به 1 دقیقه اجرا کنید : این به این معنی که کارگران خود را در حدود 15 دقیقه هر شغل را اجرا کنند. در حالیکه این ممکن است در ابتدا به نظر می رسد ایده آل ، پردازش کار اضافی به شما سود در طول زمان ناهار ، معافیت های قهوه ها ، جلسات ، و غیره این سناریو فشار قرار می دهد در زمینه های دیگر از سیستم شما مشکلات و معرفی خود را دارد. به عنوان مثال ، در مرحله اول راه اندازی خود را / پردازش زمان می گذرد ، نسبت به حق کردن ، در نتیجه از دست دادن کارایی سیستم. شبکه شما برای رفتن به اطلاعات به طور مداوم به کار کارگران مختلف هیات خسته کننده که دونگ روز خود را به کار روز جریان. شما همچنین رفتن به فشار قرار دادن بیشتر را بر روی سرور پردازش کار خود را تا آن را به ظرف از تعداد بسیار بسیار زیادی از قطعات کوچک از کار را به صورت منظم. در نهایت ، در این وضعیت اگر سرور کار خود را پایین می رود شما قصد ایجاد یک ورود پشت عظیمی از کار uncompleted در حالی که کار می تواند بزرگتر از ادامه پردازش blissfully غافل که سرور کار بود تجربه مشکلات.
در حقیقت وجود نخواهد داشت پیکربندی یک ایده آل برای راه اندازی شبکه خود ، بسیار بستگی به منابع موجود ، نوع شغل فرد ، شغل برگرد الزامات زمان ، قابلیت های شبکه ، و غیره. با این حال برخی از دستورالعمل ها خواهد بود :
- شغل حجم به طوری که هر کارگر می تواند از طریق حداقل 3-4 شغل در یک دوره 15 ساعت (به احتمال زیاد طولانی ترین مدت زمان بیکار) دریافت کنید
- بازی با حجم کار به طوری که زمان راه اندازی می شود نسبتا ناچیز به زمان پردازش (با در نظر گرفتن نقطه در بالا) مقایسه شده است.
- اگر کار می کند در دو کامل نیست مقدار زمانی (شاید کمتر) از شما انتظار آن را به کامل که چیز از دست رفته AWOL فرض آن و شروع به پردازش آن را با دیگر کارگر. این معنی است که شما ممکن است مجبور باشید تا سه بار در طول طبیعی برای آن به کار کامل (احتمالا دیگر اگر پس از آن کار می افتد). شما ممکن است بخواهید این زمان به کاهش دهد ، اما مراقب باشید نه بیش از حد آن را کاهش دهد که شما ممکن است شروع به تکثیر وظایف پردازش را به طور مرتب.
- مشاغل باید مستقل از الزامات خارج تا آنجا که امکان پذیر است. سرور کار ، به عنوان مثال ، تنها باید در شروع و پایان هر کار می شود تماس گرفت.
- آیا اشباع شبکه شما نیست ، این دو اثر منفی داشته باشد ، کارکنان خود را در طول روز را پیدا خواهد کرد با استفاده از شبکه های خسته کننده و مشکل ممکن است با اتصالات از زمان که تنها مشکل بدتر خواهد شد به عنوان شبکه خود را به شما در مقیاس با تجربه.
- شغل اطمینان می توانید بر روی کارگران را اجرا کنید. اگر شغل تبدیل بیش از حد حافظه و یا دیسک فشرده شغل فضای فشرده ساقط شروع خواهد شد و تنها چیزی که شما متوجه شده است افت در تعداد مشاغل پردازش با هیچ دلیل واقعی چرا.
نمایش نتایج : از ارائه فرصت های شغلی
وقتی ارائه نتایج یک کار مهم است که برای بررسی نتایج دیگر کارگر نشده است ارسال شده ، به خصوص اگر کارگر حاضر شده است برای برخی از زمان خواب.
هنگامی که نتایج به دست آمده ارسال شده اطمینان حاصل شود که تعداد نتایج مسابقات تعداد رکورد در کار.
همانطور که پیش از این ، و نه می تواند بیش از تاکید کرد ، ایجاد تحمل خطا کار به بازیابی و ارسال نتایج :. 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.
خلاصه
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.
Next time
In part 3 we'll create our virtual processing machine and set up our windows machines to become idle-time workers.