Skip to content

oc_mounts is updated all the time with the same information #3461

Description

@GreenArchon

Steps to reproduce

  1. Have a basic new NC11 or master instance, with local storage, mysql database
  2. Create user{1,2}
  3. Create n (5 in the following logs) folders in user1, share them with user2
  4. Logon with user2, let the first time logon and database be populated, etc.
  5. Log off user2
  6. Start logging sql queries
  7. Log on user2

Expected behaviour

Performance is relatively smooth, and already being up to date, oc_mounts is not updated

Actual behaviour

Login, and every page load is slow as **** (~10 sec on test instance with 5 folders shared)

Query log is full of

		33661 Query	UPDATE `oc_mounts` SET `storage_id` = '1', `mount_point` = '/user2/files/folder 5/', `mount_id` = NULL WHERE (`user_id` = 'user2') AND (`root_id` = 36)
		33661 Query	UPDATE `oc_mounts` SET `storage_id` = '1', `mount_point` = '/user2/files/folder 4/', `mount_id` = NULL WHERE (`user_id` = 'user2') AND (`root_id` = 35)
170212 18:00:18	33661 Query	UPDATE `oc_mounts` SET `storage_id` = '1', `mount_point` = '/user2/files/folder 3/', `mount_id` = NULL WHERE (`user_id` = 'user2') AND (`root_id` = 34)
		33661 Query	UPDATE `oc_mounts` SET `storage_id` = '1', `mount_point` = '/user2/files/folder 2/', `mount_id` = NULL WHERE (`user_id` = 'user2') AND (`root_id` = 33)
		33661 Query	UPDATE `oc_mounts` SET `storage_id` = '1', `mount_point` = '/user2/files/folder 1/', `mount_id` = NULL WHERE (`user_id` = 'user2') AND (`root_id` = 31)

Full means, for 5 folders shared, when logging in then logging out, 95 updates (or 19/share), all updating to exactly the same values.

On my (relatively small) production system, each update (ie for each share) on oc_mounts takes 0.05 to 0.5s, with 10-30 shares/user...

Server configuration

Operating system: Centos 7

Web server: apache

Database: mysql

PHP version: 5.6

Nextcloud version: (see Nextcloud admin page) 11.0.1, master (as of f9d94ed)

Updated from an older Nextcloud/ownCloud or fresh install: Irrelevant (happens in local test setup as well as production instance)

Are you using external storage, if yes which one: local

Are you using encryption: no

Are you using an external user-backend, if yes which one: Irrelevant (happens in local test setup as well as LDAP instance)

Diagnostics and hack-fix

Digging into the code, it seems that the function findChangedMounts() (lib/private/Files/Config/UserMountCache.php#L138), which determines if the db needs to be updated always returns all the mounts as having changed, because this condition is always true:

if (
	$newMount->getRootId() === $cachedMount->getRootId() &&
	(
		$newMount->getMountPoint() !== $cachedMount->getMountPoint() ||
		$newMount->getStorageId() !== $cachedMount->getStorageId() ||
		$newMount->getMountId() !== $cachedMount->getMountId()
	)
) {
	$changed[] = $newMount;
}

Looking into details, it seems that $newMount->getStorageId() is a string while $cachedMount->getStorageId() is an int (or vice versa, I don't remember), at least for the test case presented at the top.

I would have done a pull request, but I'm unsure whether getStorageID should be an int or a string. In the meantime, changing the !== to != solves the issue, and everything is fast and smooth again and I now believe the "Nextcloud 11 is faster" claims.

Note that this might be related to people having issues in #2272 and #3134.

Activity

  1. MorrisJobke commented on Feb 13, 2017

    @MorrisJobke
    Member
  2. icewind1991 commented on Feb 14, 2017

    @icewind1991
    Member

    I would have done a pull request, but I'm unsure whether getStorageID should be an int or a string.

    As the phpdoc would tell you, and int 😄

  3. GreenArchon commented on Feb 15, 2017

    @GreenArchon
    ContributorAuthor

    As the phpdoc would tell you, and int 😄

    Damn, my laziness has been busted :-P

    Very well, (unless you wanna do it) I'll prepare a pull request in the next few days (depending on free time).

  4. MorrisJobke commented on Feb 15, 2017

    @MorrisJobke
    Member

    Very well, (unless you wanna do it) I'll prepare a pull request in the next few days (depending on free time).

    Awesome :) Thanks in advance :)

  5. added this to the Nextcloud 12.0 milestone on Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions