GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — CREATE INDEX on a populated type: the sorted build sizes its runs at 3,072 bytes per entry and spills, so at 6M rows it is barely faster than the default build; in one pass it halves it · Issue #10267 · ArcadeData/arcadedb Closed Labels engineCore engine: document/schema APIperformanceseverity:minorCosmetic, documentation, edge case, or a workaround existssql Milestone Description
Setup: the documents lane of my benchmark, scaled to TPC-H SF1's
The sorted build logs the reason. With the budget it resolves here,
(The heap peaks are sampled every 20 ms and include garbage, so they are rough.) The one-pass build peaks in the same range as the spilling one and below the default build. It does not need four times the memory: what the 3,072-byte estimate limits is the run size. Where the time goes (JFR execution samples of one build each, main):
Two suggestions, either of which shortens the build:
For scale: on my benchmark host the documents lane's index build at SF1 took 6.13 s for ArcadeDB 26.10.1 (embedded) against 1.45 s for PostgreSQL, the median of 3 runs each in my current pass. The laptop numbers above are for ratios only. IndexBuildModes.java// type: LineItem with the lane's column types and BUCKETS, N rows, l_shipdate a STRING 'YYYY-MM-DD' over TPC-H's 2,526 ship // dates; then CREATE INDEX ON LineItem (l_shipdate) NOTUNIQUE timed in the DEFAULT and the SORTED build mode, alternating on // the same data (DROP INDEX between), each build checked: entries = N and a one-year range count = the generator's count. // java IndexBuildModes.java <dir> <rows> <buckets> <reps> [modes=DEFAULT,SORTED; SORTED_P<n> = the Java API's SORTED build with n threads] import com.arcadedb.database.*; import com.arcadedb.index.*; import com.arcadedb.schema.*; import java.time.LocalDate; import java.util.*; public class IndexBuildModes { public static void main(String[] a) throws Exception { String dir = a[0]; long n = Long.parseLong(a[1]); int buckets = Integer.parseInt(a[2]), reps = Integer.parseInt(a[3]); String[] order = (a.length > 4 ? a[4] : "DEFAULT,SORTED").split(","); DatabaseFactory f = new DatabaseFactory(dir); if (f.exists()) f.open().drop(); Database db = f.create(); db.command("sql", "CREATE DOCUMENT TYPE LineItem BUCKETS " + buckets).close(); String[][] cols = { {"l_orderkey","LONG"},{"l_partkey","LONG"},{"l_suppkey","LONG"},{"l_quantity","DOUBLE"},{"l_extendedprice","DOUBLE"}, {"l_discount","DOUBLE"},{"l_tax","DOUBLE"},{"l_returnflag","STRING"},{"l_linestatus","STRING"},{"l_shipdate","STRING"},{"l_shipmode","STRING"} }; for (String[] c : cols) db.command("sql", "CREATE PROPERTY LineItem." + c[0] + " " + c[1]).close(); LocalDate d0 = LocalDate.of(1992, 1, 2); int days = (int) (LocalDate.of(1998, 12, 1).toEpochDay() - d0.toEpochDay()) + 1; String[] dates = new String[days]; for (int i = 0; i < days; i++) dates[i] = d0.plusDays(i).toString(); String[] modes = { "AIR", "FOB", "MAIL", "RAIL", "REG AIR", "SHIP", "TRUCK" }; Random r = new Random(42); long inYear = 0; long t0 = System.nanoTime(); final int BATCH = 20_000; for (long i = 0; i < n; ) { db.begin(); for (int b = 0; b < BATCH && i < n; b++, i++) { String sd = dates[r.nextInt(days)]; if (sd.compareTo("1994-01-01") >= 0 && sd.compareTo("1995-01-01") < 0) inYear++; db.newDocument("LineItem").set("l_orderkey", i / 4).set("l_partkey", (long) r.nextInt(200_000)).set("l_suppkey", (long) r.nextInt(10_000)) .set("l_quantity", (double) (1 + r.nextInt(50))).set("l_extendedprice", 900.0 + r.nextInt(100_000) / 1.0).set("l_discount", r.nextInt(11) / 100.0) .set("l_tax", r.nextInt(9) / 100.0).set("l_returnflag", r.nextBoolean() ? "N" : "R").set("l_linestatus", r.nextBoolean() ? "O" : "F") .set("l_shipdate", sd).set("l_shipmode", modes[r.nextInt(modes.length)]).save(); } db.commit(); } System.out.printf("LOAD rows %d buckets %d in %.1f s; distinct ship dates %d; rows in 1994: %d%n", n, buckets, (System.nanoTime() - t0) / 1e9, days, inYear); for (int rep = 1; rep <= reps; rep++) for (String mode : rotate(order, rep - 1)) { if (db.getSchema().existsIndex("LineItem[l_shipdate]")) db.getSchema().dropIndex("LineItem[l_shipdate]"); System.gc(); Thread.sleep(2000); jdk.jfr.Recording jr = null; if (System.getenv("JFR_DIR") != null && rep == 1) { jr = new jdk.jfr.Recording(); jr.enable("jdk.ExecutionSample").withPeriod(java.time.Duration.ofMillis(5)); jr.start(); } var mx = java.lang.management.ManagementFactory.getMemoryMXBean(); System.gc(); Thread.sleep(500); final long base = mx.getHeapMemoryUsage().getUsed(); final long[] peak = { base }; final boolean[] run = { true }; Thread sampler = new Thread(() -> { while (run[0]) { peak[0] = Math.max(peak[0], mx.getHeapMemoryUsage().getUsed()); try { Thread.sleep(20); } catch (InterruptedException ie) { return; } } }); sampler.setDaemon(true); sampler.start(); long s = System.nanoTime(); if (mode.startsWith("SORTED_")) { // SORTED_P<threads>[_M<GiB>]: the Java API's sorted build, with a thread count and a memory budget var m = java.util.regex.Pattern.compile("SORTED_P(\\d+)(?:_M(\\d+))?").matcher(mode); if (!m.matches()) throw new IllegalArgumentException(mode); var tb = db.getSchema().buildTypeIndex("LineItem", new String[] { "l_shipdate" }).withBuildMode(IndexBuildMode.SORTED).withBuildParallelism(Integer.parseInt(m.group(1))); if (m.group(2) != null) tb = tb.withBuildMemoryBudget(Long.parseLong(m.group(2)) << 30); tb.withType(Schema.INDEX_TYPE.LSM_TREE).withUnique(false).create(); } else db.command("sql", "CREATE INDEX ON LineItem (l_shipdate) NOTUNIQUE" + (mode.equals("SORTED") ? " METADATA {buildMode: 'SORTED'}" : "")).close(); double ms = (System.nanoTime() - s) / 1e6; run[0] = false; sampler.join(); long heapMb = (peak[0] - base) >> 20; if (jr != null) { jr.stop(); jr.dump(java.nio.file.Path.of(System.getenv("JFR_DIR"), "build-" + mode + ".jfr")); jr.close(); } long entries = db.getSchema().getIndexByName("LineItem[l_shipdate]").countEntries(); long q; try (var rs = db.query("sql", "SELECT count(*) AS c FROM LineItem WHERE l_shipdate >= '1994-01-01' AND l_shipdate < '1995-01-01'")) { q = ((Number) rs.next().getProperty("c")).longValue(); } System.out.printf("RESULT rep %d mode %s build_ms %.0f heap_peak_over_base_mb %d entries %d (want %d) year_count %d (want %d) %s%n", rep, mode, ms, heapMb, entries, n, q, inYear, entries == n && q == inYear ? "ok" : "WRONG"); } db.close(); } static String[] rotate(String[] m, int k) { String[] o = new String[m.length]; for (int i = 0; i < m.length; i++) o[i] = m[(i + k) % m.length]; return o; } } Activity
MetadataMetadataAssigneesLabelsengineCore engine: document/schema APIperformanceseverity:minorCosmetic, documentation, edge case, or a workaround existssql TypeProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |