Easy backup of the long ruby ​​process

I plan to launch a ruby ​​process, which can take a month. If possible, I would like to make sure that dimming or pressing the wrong button will not cost me a whole month.

Is there an easy way to periodically save the state of a program to disk? (Techniques that require more effort include adding code that marshals everything except the database, or perhaps using a virtual machine for the process’s operating system).

(For those interested: the process involves analyzing an XML file with several gigabytes on a well-known website, processing some information and storing information in the ActiveRecord database as it moves along.)

Edit : this project , and the XML file is pages-articles.xml (for example, enwiki-20090306-pages-articles.xml). Nothing proprietary, I just didn't want to be in Plz halp mode. The first pass gets a list of page names on Wikipedia, the next pass determines the first link from each page to another page, and then I calculate some statistics.

Continuing from where I left off, as some defendants claim, is probably an acceptable option. If it crashes during the first pass, I can probably restart it, telling him not to add existing entries. If it works during the second pass, I must ask him to create links for pages on which their link has not yet been calculated. If it crashes while calculating statistics, I can just recalculate the statistics.

Other editing . A more general version of this question is asked in Save process memory for later use? . It seems that you cannot easily support lengthy processes.

+3
source share
5 answers

?. , .

0

- , , YAML ( . yaml.org). YAML .to_yml, , , yml. , , . , yaml , .

require "yaml"
def backup(objects_im_Using)
  out_file = File.open("prefix"+Time.now.strftime('%Y-%M-%d')+".yml","w")
  objects_im_Using.each {|object| out_file 

( , , - .)

, . !

+1

, ( ), .

- ? ?

, , , 2 AR- . , ( - ), CSV 16 "" . Fragment, . , , , . 30 .

XML- , ( , , ) . , SAX - , , XML , . , , - , .

, ?

+1

, , , .

, , , , ? , - , , ( - ).

+1

OK. , , , . , , .

, , , , , , , , .

, .

. (-, , ) XML ; 21 . . <page>, : , (, , ) , , id. - XML -, . String #, open close . , .

21GB , , , : . . , , 10K. - GB , .

script, 250 000 / . "" ( ) ":" ( , ). , , . 30 . 5,23 ( , : , ), 1.03 (. ) 20 . Ruby (MRI) 1.8.6, Windows Vista, 2GHz Core 2 Duo. , .

3 :

Anarchism, [[political philosophy]]
Autism, [[Neurodevelopmental disorder|brain development disorder]]
Albedo, [[Sun]]
0

Source: https://habr.com/ru/post/1706021/


All Articles