Comparison

util/startup.lua @ 11073:5691b9773c5b 0.11

util.startup: Configure the GC on startup, using the config or built-in defaults
author Matthew Wild <mwild1@gmail.com>
date Mon, 15 Jun 2020 14:16:34 +0100
parent 10947:801b9d5957a6
child 11074:3473bc8d80c9
child 11539:3413fea9e6db
comparison
equal deleted inserted replaced
11072:02227c5d0c59 11073:5691b9773c5b
9 local config = require "core.configmanager"; 9 local config = require "core.configmanager";
10 10
11 local dependencies = require "util.dependencies"; 11 local dependencies = require "util.dependencies";
12 12
13 local original_logging_config; 13 local original_logging_config;
14
15 local default_gc_params = { mode = "incremental", threshold = 105, speed = 250 };
14 16
15 local short_params = { D = "daemonize", F = "no-daemonize" }; 17 local short_params = { D = "daemonize", F = "no-daemonize" };
16 local value_params = { config = true }; 18 local value_params = { config = true };
17 19
18 function startup.parse_args() 20 function startup.parse_args()
542 print(""); 544 print("");
543 os.exit(1); 545 os.exit(1);
544 end 546 end
545 end 547 end
546 548
549 function startup.init_gc()
550 -- Apply garbage collector settings from the config file
551 local gc = require "util.gc";
552 local gc_settings = config.get("*", "gc") or { mode = default_gc_params.mode };
553
554 local ok, err = gc.configure(gc_settings, default_gc_params);
555 if not ok then
556 log("error", "Failed to apply GC configuration: %s", err);
557 return nil, err;
558 end
559 return true;
560 end
561
547 function startup.make_host(hostname) 562 function startup.make_host(hostname)
548 return { 563 return {
549 type = "local", 564 type = "local",
550 events = prosody.events, 565 events = prosody.events,
551 modules = {}, 566 modules = {},
571 startup.parse_args(); 586 startup.parse_args();
572 startup.init_global_state(); 587 startup.init_global_state();
573 startup.read_config(); 588 startup.read_config();
574 startup.force_console_logging(); 589 startup.force_console_logging();
575 startup.init_logging(); 590 startup.init_logging();
591 startup.init_gc();
576 startup.setup_plugindir(); 592 startup.setup_plugindir();
577 startup.setup_datadir(); 593 startup.setup_datadir();
578 startup.chdir(); 594 startup.chdir();
579 startup.read_version(); 595 startup.read_version();
580 startup.switch_user(); 596 startup.switch_user();
591 -- previous steps to have already been performed 607 -- previous steps to have already been performed
592 startup.parse_args(); 608 startup.parse_args();
593 startup.init_global_state(); 609 startup.init_global_state();
594 startup.read_config(); 610 startup.read_config();
595 startup.init_logging(); 611 startup.init_logging();
612 startup.init_gc();
596 startup.sanity_check(); 613 startup.sanity_check();
597 startup.sandbox_require(); 614 startup.sandbox_require();
598 startup.set_function_metatable(); 615 startup.set_function_metatable();
599 startup.check_dependencies(); 616 startup.check_dependencies();
600 startup.load_libraries(); 617 startup.load_libraries();