Skip to content

Conversation

@kayrus
Copy link
Contributor

@kayrus kayrus commented May 3, 2016

Instead of retrieving all properties for each units, we will pass list of
units to GetUnitsStates method and receive units' states.

My first decision was to implement GetUnitsProperties method, but it appeared that this change requires lot of work or I mixed up by dbus code. At least I didn't find the way to iterate vtables inside src/core/dbus-manager.c.

Resolves coreos/fleet#1418 and coreos/fleet#1564
Relates to #3142

@poettering
Copy link
Member

Hmm, shouldn't we rather add ListUnitsByName() or so, that is like ListUnits() but allows you to pass in precisely which units you want to cover? It would be a lot like ListUnitsByPatterns(), except it would not resolve patterns, nor care about states, but just dump the entries for the names listed, but in the same format as ListUnits()?

@poettering poettering added pid1 needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer labels May 4, 2016
@kayrus
Copy link
Contributor Author

kayrus commented May 4, 2016

@poettering ListUnits returns data which is loaded in systemd memory. GetUnitsStates works with units which are not in memory or have inactive state (and even not existing in the system). Of course I can add extra code into existing list_units_filtered function. It will be triggered only when patterns is not empty. But in this case we have patterns, not real unit names. So the solution would be to use patterns as a filter for unit_file_get_list and then loop through these unit files and execute manager_load_unit function for each of these units.

I was not quite sure whether I should implement such logic. Let me know what you think.

@poettering
Copy link
Member

Well, the memory management model of systemd is really that we'll implicitly load all units that people request operations on. Hence, whether something is loaded or not is mostly a detail of the implementation – with one exception: ListUnits() only tells you about units currently loaded.

So, I think this should exposed as ListUnitsByName(). That said, there's probably no need to work this into list_units_filtered(), since what we loop around is quite different. That said, I think the code that's run inside the loop and ultimately adds the unit data into the dbus array could probably be shared, by splitting it out into a new funciton that is used by both.

@kayrus
Copy link
Contributor Author

kayrus commented May 4, 2016

@poettering just clarifying, do you mean we have to implement new method called ListUnitsByName, but not modification of the ListUnitsByPatterns? If so, should I try to retrieve units info from the memory first and if unit doesn't exists and the pattern is a valid unit name, try to use manager_load_unit? As a result there will be new shared function which will contain this loop (with minor modifications explained above).

@poettering
Copy link
Member

Well, it's not about "having to" really. A convincing patch always wins. But I think that exposing this as ListUnitsByName and leaving ListUnitsByPatterns as it is is fully OK.

Always just use manager_load_unit(). It will load the unit if necessary, and otherwise just return the unit immediately.

And yeah, the second half of that loop you linked I'd probably turn into a function of its own, and reuse for this loop. I.e. the part where the data is pulled from the unit and written to the dbus message.

@kayrus kayrus force-pushed the kayrus/get_units_properties branch from ec683a7 to df731ff Compare May 11, 2016 11:39
@kayrus kayrus changed the title core: added GetUnitsStates dbus method core: added ListUnitsByNames dbus method May 11, 2016
@kayrus
Copy link
Contributor Author

kayrus commented May 11, 2016

@poettering done.

This new method returns information by unit names. Instead of ListUnitsByPatterns
this method returns information of inactive and even unexisting units.
Moved dbus unit reply logic into a separate shared function.
Resolves coreos/fleet#1418
@kayrus
Copy link
Contributor Author

kayrus commented May 11, 2016

Some tests on 500 inactive units:

$ time busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager ListUnitsByNames as 1000 hello@{1..1000}.service > /dev/null

real    0m0.204s
user    0m0.009s
sys     0m0.000s
$ time busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager ListUnitsByNames as 1000 hello@{1..1000}.service > /dev/null

real    0m0.178s
user    0m0.007s
sys     0m0.001s
$ time busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager ListUnitsByNames as 1000 hello@{1..1000}.service > /dev/null

real    0m0.397s
user    0m0.009s
sys     0m0.000s

and without the patch, using old org.freedesktop.DBus.Properties GetAll method:

$ time for i in {1..1000}; do busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/hello_40${i}_2eservice org.freedesktop.DBus.Properties GetAll "s" "" > /dev/null ;done 

real    0m11.483s
user    0m0.852s
sys     0m0.469s
$ time for i in {1..1000}; do busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/hello_40${i}_2eservice org.freedesktop.DBus.Properties GetAll "s" "" > /dev/null ;done 

real    0m12.631s
user    0m0.906s
sys     0m0.468s
$ time for i in {1..1000}; do busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/hello_40${i}_2eservice org.freedesktop.DBus.Properties GetAll "s" "" > /dev/null ;done 

real    0m13.253s
user    0m0.856s
sys     0m0.504s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1

Development

Successfully merging this pull request may close these issues.

2 participants