git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/gitlab: Add Sidekiq MemoryKiller support

Restart sidekiq automatically when it consumes too much memory. See https://docs.gitlab.com/ee/administration/operations/sidekiq_memory_killer.html for details.

commit306fc0648b99682219049c95e2182f2c668f61e6 authortalyz <kim.lindberger@gmail.com> dateThu 8 Apr 2021, 19:01 (6 years ago) parent6230936
1 file changed+51−2
nixos/modules/services/misc/gitlab.nix+51−2
nixos/modules/services/misc/gitlab.nix+51−2
@@ -708,6 +708,49 @@ in {
708708 '';
709709 };
710710
711+ sidekiq.memoryKiller.enable = mkOption {
712+ type = types.bool;
713+ default = true;
714+ description = ''
715+ Whether the Sidekiq MemoryKiller should be turned
716+ on. MemoryKiller kills Sidekiq when its memory consumption
717+ exceeds a certain limit.
718+
719+ See <link xlink:href="https://docs.gitlab.com/ee/administration/operations/sidekiq_memory_killer.html"/>
720+ for details.
721+ '';
722+ };
723+
724+ sidekiq.memoryKiller.maxMemory = mkOption {
725+ type = types.int;
726+ default = 2000;
727+ apply = x: builtins.toString (x * 1024);
728+ description = ''
729+ The maximum amount of memory, in MiB, a Sidekiq worker is
730+ allowed to consume before being killed.
731+ '';
732+ };
733+
734+ sidekiq.memoryKiller.graceTime = mkOption {
735+ type = types.int;
736+ default = 900;
737+ apply = x: builtins.toString x;
738+ description = ''
739+ The time MemoryKiller waits after noticing excessive memory
740+ consumption before killing Sidekiq.
741+ '';
742+ };
743+
744+ sidekiq.memoryKiller.shutdownWait = mkOption {
745+ type = types.int;
746+ default = 30;
747+ apply = x: builtins.toString x;
748+ description = ''
749+ The time allowed for all jobs to finish before Sidekiq is
750+ killed forcefully.
751+ '';
752+ };
753+
711754 extraConfig = mkOption {
712755 type = types.attrs;
713756 default = {};
@@ -1049,7 +1092,11 @@ in {
10491092 ] ++ optional (cfg.databaseHost == "") "postgresql.service";
10501093 wantedBy = [ "gitlab.target" ];
10511094 partOf = [ "gitlab.target" ];
1052− environment = gitlabEnv;
1095+ environment = gitlabEnv // (optionalAttrs cfg.sidekiq.memoryKiller.enable {
1096+ SIDEKIQ_MEMORY_KILLER_MAX_RSS = cfg.sidekiq.memoryKiller.maxMemory;
1097+ SIDEKIQ_MEMORY_KILLER_GRACE_TIME = cfg.sidekiq.memoryKiller.graceTime;
1098+ SIDEKIQ_MEMORY_KILLER_SHUTDOWN_WAIT = cfg.sidekiq.memoryKiller.shutdownWait;
1099+ });
10531100 path = with pkgs; [
10541101 postgresqlPackage
10551102 git
@@ -1061,13 +1108,15 @@ in {
10611108 # Needed for GitLab project imports
10621109 gnutar
10631110 gzip
1111+
1112+ procps # Sidekiq MemoryKiller
10641113 ];
10651114 serviceConfig = {
10661115 Type = "simple";
10671116 User = cfg.user;
10681117 Group = cfg.group;
10691118 TimeoutSec = "infinity";
1070− Restart = "on-failure";
1119+ Restart = "always";
10711120 WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
10721121 ExecStart="${cfg.packages.gitlab.rubyEnv}/bin/sidekiq -C \"${cfg.packages.gitlab}/share/gitlab/config/sidekiq_queues.yml\" -e production";
10731122 };