[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#925160: systemd: user session slow to start (11 seconds)



control: summary -1 0 slow to start user ssh session (11 seconds)

Hi,

I reopened this bug since the current unstable package isn't good enough
and requires some touch up to get accepted for testing.

Problem:
========
 * The default desktop Debain install is Gnome-wayland.
 * Some localization tasks pull in im-config (its important)
 * The testing had im-config=0.39-1
 * Im-config=0.39-1 caused major degradation to the ssh login with
   11 unresponsive latency under wayland+systemd.
 * The root cause was the slow script run by im-config during the start of
   a new process to set its environment variable using the systemd's
   systemd.environment-generator(7).
 * this performance degradation of the default system is unacceptable.


Bug #925160 back ground:
========================
Many unnoticed performance bugs crept into im-config to cause this bug.

 * Nov 2011 (version 0.5) -- older than oldstable/jessie
   Since im-config is ARCH=all package, it used "*" as the path part for
   the multiarch such as x86_64-linux-gnu 
   --> This should have been "*-*-*" instead of just "*"
 * Feb 2015 (version 0.27-2) jessie released version
 * Dec 2016 (version 0.30-1) stretch released version
 * Bug #905129: im-config: Wrongly run shell scripts with user's shell
                interpreter, raises error with zsh (Jul 2018)
   This was really a problem of KDE + sddm.
 * Aug 2018 (0.37-1) -- during buster development cycle
   im-config worked around bug #905129 by replacing shell glob with a
   shell function call which runs script with "find" command.
   --> This should have been worked around by using the simple one liner: 
       if [ x != x"$ZSH_NAME" ]; then emulate -R sh ; fi
 * Mar 2019 (version 0.40-1)
   Patch provided by Y. Yoshino was applied to make im-config useful for
   Gnome-wayland.  Since gnome-session has no easy hook script
   mechanism like /etc/X11/Xsession.d/* files for X, this patch decided
   to use systemd.environment-generator(7) to set the user environment.
   --> This script run the problematic slow code twice which made situation
       worse.
   --> This startup code should have been disabled if it finds
       ibus-daemon just as gnome-session (main.c) does.
   --> This startup code should run only when it finds
       XDG_SESSION_TYPE=wayland (ideally -- but can't check it if
       systemd.environment-generator is used)
 * Bug #925160 systemd: user session slow to start (11 seconds) (Mar 2019)
   Since 0.40-1 used systemd.environment-generator, the hook scrip was
   run even for ssh login and delay of 11 seconds was noticed. ssh with
   X-session doesn't have this problem for ssh and 11 second during X
   start up may not be as annoying.

How to solve Bug #925160:
=========================
 * Fix glob to use "*-*-*"
 * Use "emulate -R sh" trick (not script with "find") for zsh
 * save environment variables to avoid running the problematic slow code
   twice
 * check existence of ibus-daemon and disable systemd.environment-generator
   script if you find it.


Technical reference:
====================
 $ cd /usr/lib
 $ ( ls -1d * ; ls -1d * )|wc -l
734
 $ ls -1d *-*   |wc -l
74
 $ ls -1d *-*-* |wc -l
18

So not running slow glob twice and changing "*" --> "*-*-*" can improve
speed 40 times!

Shell glob approach is faster than script with "find"

Future vision:
==============
I see 2 parts of code which may be patched to make cleaner solution
 * gnome-session ibus related environment variable setting
 * gnome-shell:  ibus starting code
But that is for future.

im-config's complicated time consuming code may be useless to start with
from today's situation since settings such as:
  GTK_IM_MODULE=xim
  QT4_IM_MODULE=xim
are not good idea .  It is usually a source of lost key input etc.
It's now better to use settings such as:
  GTK_IM_MODULE=ibus
  QT4_IM_MODULE=ibus

This simplify code greatly but doing this may be too late for buster
under freeze.

Osamu


Reply to: