Commit 28b07427 authored by Lucas Nussbaum's avatar Lucas Nussbaum

Cache the parsing of all JSON files (to avoid parsing it several times per run)

=> huge performance improvement
parent 3ba0847e
...@@ -12,7 +12,7 @@ class CPUParametersGenerator < WikiGenerator ...@@ -12,7 +12,7 @@ class CPUParametersGenerator < WikiGenerator
table_columns = ["Installation date", "Site", "Cluster", "CPU Family", "CPU Version", "Microarchitecture", "Frequency", "Server type", "HT enabled", "Turboboost enabled", "P-State driver", "C-State driver"] table_columns = ["Installation date", "Site", "Cluster", "CPU Family", "CPU Version", "Microarchitecture", "Frequency", "Server type", "HT enabled", "Turboboost enabled", "P-State driver", "C-State driver"]
table_data = [] table_data = []
global_hash = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__))) global_hash = get_global_hash
# Loop over Grid'5000 sites # Loop over Grid'5000 sites
global_hash["sites"].sort.to_h.each { |site_uid, site_hash| global_hash["sites"].sort.to_h.each { |site_uid, site_hash|
......
...@@ -12,7 +12,7 @@ class DiskReservationGenerator < WikiGenerator ...@@ -12,7 +12,7 @@ class DiskReservationGenerator < WikiGenerator
def generate_content def generate_content
table_columns = ["Site", "Cluster", "Number of nodes", "Number of reservable disks per node"] table_columns = ["Site", "Cluster", "Number of nodes", "Number of reservable disks per node"]
table_data = [] table_data = []
global_hash = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__))) global_hash = get_global_hash
# Loop over Grid'5000 sites # Loop over Grid'5000 sites
global_hash["sites"].sort.to_h.each { |site_uid, site_hash| global_hash["sites"].sort.to_h.each { |site_uid, site_hash|
......
...@@ -12,7 +12,7 @@ class G5KHardwareGenerator < WikiGenerator ...@@ -12,7 +12,7 @@ class G5KHardwareGenerator < WikiGenerator
end end
def generate_content def generate_content
@global_hash = load_yaml_file_hierarchy(File.expand_path('../../input/grid5000/', File.dirname(__FILE__))) @global_hash = get_global_hash
@site_uids = G5K::SITES @site_uids = G5K::SITES
@generated_content = "__NOEDITSECTION__\n" @generated_content = "__NOEDITSECTION__\n"
......
...@@ -59,8 +59,6 @@ end ...@@ -59,8 +59,6 @@ end
#Defines global Grid5000 helpers (TODO move to its own file once it is big enough) #Defines global Grid5000 helpers (TODO move to its own file once it is big enough)
module G5K module G5K
SITES = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__)))['sites'].keys.sort
# This method compacts an array of integers as follows # This method compacts an array of integers as follows
# nodeset([2,3,4,7,9,10,12]) returns the string '[2-4,<wbr>7,<wbr>9-10,<wbr>12]' # nodeset([2,3,4,7,9,10,12]) returns the string '[2-4,<wbr>7,<wbr>9-10,<wbr>12]'
# where <wbr> is a hidden tag that enables carriage return in wikimedia # where <wbr> is a hidden tag that enables carriage return in wikimedia
...@@ -108,6 +106,16 @@ module G5K ...@@ -108,6 +106,16 @@ module G5K
return (count == 1 || word[-1] == 's') ? word : word + 's' return (count == 1 || word[-1] == 's') ? word : word + 's'
end end
@@global_hash = nil
def self.get_global_hash
if @@global_hash.nil?
@@global_hash = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__)))
end
# return a deep copy of global_hash
return Marshal.load(Marshal.dump(@@global_hash))
end
SITES = get_global_hash['sites'].keys.sort
end end
#Defines MediaWiki helpers #Defines MediaWiki helpers
......
...@@ -173,7 +173,7 @@ class OarPropertiesGenerator < WikiGenerator ...@@ -173,7 +173,7 @@ class OarPropertiesGenerator < WikiGenerator
end end
def generate_content def generate_content
refapi = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__))) refapi = get_global_hash
#Properties generated from oar-properties generator #Properties generated from oar-properties generator
props = {} props = {}
G5K::SITES.each{ |site_uid| G5K::SITES.each{ |site_uid|
......
...@@ -160,7 +160,7 @@ def sort_data(data, key) ...@@ -160,7 +160,7 @@ def sort_data(data, key)
end end
def get_hardware(sites) def get_hardware(sites)
global_hash = load_yaml_file_hierarchy(File.expand_path("../../input/grid5000/", File.dirname(__FILE__))) global_hash = G5K::get_global_hash
# Loop over each cluster of the site # Loop over each cluster of the site
hardware = {} hardware = {}
......
...@@ -11,6 +11,10 @@ class WikiGenerator ...@@ -11,6 +11,10 @@ class WikiGenerator
@page_name = page_name @page_name = page_name
end end
def get_global_hash
return G5K::get_global_hash
end
def login(options) def login(options)
if (options[:user] && options[:pwd]) if (options[:user] && options[:pwd])
@mw_client.log_in(options[:user], options[:pwd]) @mw_client.log_in(options[:user], options[:pwd])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment