Bug 1010006

Summary: PERF: Fetch of districts is very slow
Product: OpenShift Online Reporter: Dan McPherson <dmcphers>
Component: PodAssignee: Dan McPherson <dmcphers>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 2.xCC: jhou
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-17 13:29:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Dan McPherson 2013-09-19 16:53:41 UTC
Description of problem:

The initialize method for district is calling save!  So if we query a list of 50 districts we do 50 saves.  This is taking ~300ms in prod for every app create.


Version-Release number of selected component (if applicable):


How reproducible:
100%


Steps to Reproduce:
1. Do anything that gets a district
2.
3.

Actual results:
It saves the district


Expected results:
It shouldn't save the district


Additional info:

Comment 1 Dan McPherson 2013-09-19 18:53:44 UTC
Correction:  It looks like new isn't being called by mongoid on subsequent fetches.  Looks like it might just be the amount of data being returned that's the issue.

Comment 2 Dan McPherson 2013-09-19 21:20:52 UTC
The fix here is not to include available_uids when finding a node during app create.

Comment 3 Dan McPherson 2013-09-19 21:21:28 UTC
https://github.com/openshift/origin-server/pull/3667

Comment 4 Jianwei Hou 2013-09-22 05:21:01 UTC
Verified on devenv_3810

1. Create 51 disctricst with oo-admin-ctl-district
libra_rs:PRIMARY> db.districts.count()
51

2. Connect to datastore, verify the unique indexes have been enabled on the district collection
libra_rs:PRIMARY> db.districts.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"ns" : "openshift_broker_dev.districts",
		"name" : "_id_"
	},
	{
		"v" : 1,
		"key" : {
			"name" : 1
		},
		"unique" : true,
		"ns" : "openshift_broker_dev.districts",
		"name" : "name_1"
	},
	{
		"v" : 1,
		"key" : {
			"uuid" : 1
		},
		"unique" : true,
		"ns" : "openshift_broker_dev.districts",
		"name" : "uuid_1"
	},
	{
		"v" : 1,
		"key" : {
			"gear_size" : 1
		},
		"ns" : "openshift_broker_dev.districts",
		"name" : "gear_size_1"
	}
]
3. Query districts
irb(main):007:0> require '/var/www/openshift/broker/config/environment'
irb(main):007:0> require '/opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-controller-1.15.0/app/models/district.rb'
irb(main):052:0> a = Time.now;District.find_all();b = Time.now - a
=> 0.671984381
irb(main):053:0> a = Time.now;District.find_all(nil,false);b = Time.now - a
=> 0.005056106

Takes 5ms when uuids are not included in the query criterion。