summaryrefslogtreecommitdiff
path: root/tests/functional-tests/ipc/test-class-signal-performance.vala
blob: 02e2155336768ebbb040b2836f8a8ba86108ba47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

using Tracker;
using Tracker.Sparql;

const int max_signals = 1000;
// const int max_signals = 10000;
const string title_data = "title";

// Always start this test AFTER DOING tracker-control -r. The test IS NOT
// deleting existing resources, so you CAN'T RUN IT TWICE unless you clear
// the database before starting it the second time.

// Testreport of Aug 25, 2010 by Philip
// ------------------------------------
// On Aug 25 the difference between using tracker-store on master and the
// tracker-store of class-signal, and then letting this wait until all 10000
// (in case of max_signals = 10000) insert queries' signals arrived (you'll
// have in total 20002 events in the signals in both tracker-store versions)
// was: 20s for class-signals (new class signal) and 23s for master (old class
// signals). Measured using this performance test.
//
// Memory usage of class-signal (new class signal)'s tracker-store:
// Low: VmRSS: 8860 Kb -- Max: VmRSS: 14116 kB
//
// Memory usage of master (old class signal)'s tracker-store:
// Low: VmRSS: 8868 Kb -- Max: VmRSS: 14060 kB


struct Event {
	int graph_id;
	int subject_id;
	int pred_id;
	int object_id;
}

[DBus (name = "org.freedesktop.Tracker1.Resources")]
private interface Resources : GLib.Object {
	[DBus (name = "GraphUpdated")]
	public signal void graph_updated (string class_name, Event[] deletes, Event[] inserts);

	[DBus (name = "SparqlUpdate")]
	public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
}

[DBus (name = "org.freedesktop.Tracker1.Resources.Class")]
private interface ResourcesClass : GLib.Object {
	[DBus (name = "SubjectsAdded")]
	public signal void subjects_added (string [] subjects);
	[DBus (name = "SubjectsChanged")]
	public signal void subjects_changed (string [] subjects, string [] preds);
}

public class TestApp {
	static DBus.Connection dbus_connection;
	static Resources resources_object;
	static ResourcesClass class_object;
	MainLoop loop;
	bool initialized = false;
	Sparql.Connection con;
	int count = 0;
	GLib.Timer t;

	public TestApp ()
	requires (!initialized) {
		try {
			con = Tracker.Sparql.Connection.get();
			dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
			resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
			                                                           "/org/freedesktop/Tracker1/Resources",
			                                                           "org.freedesktop.Tracker1.Resources");

			class_object = (ResourcesClass) dbus_connection.get_object ("org.freedesktop.Tracker1",
		                                                                "/org/freedesktop/Tracker1/Resources/Classes/nmm/MusicPiece",
		                                                                "org.freedesktop.Tracker1.Resources.Class");

			class_object.subjects_added.connect (on_subjects_added);
			class_object.subjects_changed.connect (on_subjects_changed);

			resources_object.graph_updated.connect (on_graph_updated_received);
			t = new GLib.Timer ();
			
		} catch (Sparql.Error e) {
			warning ("Could not connect to D-Bus service: %s", e.message);
			initialized = false;
			return;
		} catch (DBus.Error e) {
			warning ("Could not connect to D-Bus service: %s", e.message);
			initialized = false;
			return;
		}
		initialized = true;
	}

	private void on_subjects_changed (string [] subjects, string [] preds) {
		foreach (string s in subjects)
			count++;

		//if (count == 20002)
			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void on_subjects_added (string [] subjects) {
		foreach (string s in subjects)
			count++;

		//if (count == 20002)
			print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void on_graph_updated_received (string class_name, Event[] deletes, Event[] inserts) {
		foreach (Event insert in inserts)
			count++;
		//if (count == 20002)
			print ("New class signal count=%d time=%lf\n", count, t.elapsed ());
	}

	private void insert_data () {
		int i;

		t.start();
		for (i = 0; i <= max_signals; i++) {
			string upqry = "INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, title_data, i);
			resources_object.sparql_update_async (upqry);
		}
	}

	private bool in_mainloop () {
		insert_data ();
		return false;
	}

	public int run () {
		loop = new MainLoop (null, false);
		Idle.add (in_mainloop);
		loop.run ();
		return 0;
	}
}

int main (string[] args) {
	TestApp app = new TestApp ();

	return app.run ();
}