Skip to content

Instantly share code, notes, and snippets.

@ali-ince
Created October 18, 2017 12:52
Show Gist options
  • Save ali-ince/cf554c9e1eeba02252236dd59ab3a4a8 to your computer and use it in GitHub Desktop.
Save ali-ince/cf554c9e1eeba02252236dd59ab3a4a8 to your computer and use it in GitHub Desktop.
Neo4j - Large Results
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Neo4j.Driver.V1;
namespace Test
{
class Program
{
private static readonly int[] RecordCounts = {100, 500, 1000, 5000, 10000, 50000};
private static readonly string BoltUrl = Environment.GetEnvironmentVariable("BOLT_URL") ?? "bolt://127.0.0.1:7687";
private static readonly string BoltUsername = Environment.GetEnvironmentVariable("BOLT_USERNAME") ?? "neo4j";
private static readonly string BoltPassword = Environment.GetEnvironmentVariable("BOLT_PASSWORD") ?? "neo4j";
private const string BoltQuery = @"UNWIND RANGE(1,{0}) AS N RETURN N, null, true, false, -2147483650, -32770, -130, -18, 126, 32765, 2147483645, 2147483650, 1.1, -1.1, """", ""1"", ""1234567890"",
""ppkXUYYqy9ENl9caIvQyRsO19jXy4LhZHHVZMyUBQjbHJXlkv2vvUfeowOOujxTxJxXufzzGLFjn35w4zFpR4pRnlM3a1AkwV0L6jCj0pWic7bPBwiiasjJTieiynvE9CIHBwdyfGAUW4YMrGR5mBZwkMWIZlDQ9
hmLD3ohSlzoYp8ilj4pDreho83L5eSobYOGOKMn3ytLIKawzjO21eCIVAAXT5DmESMfoTixDLQbi9HGrNEzm56NLQjeTEsKxEKPHFDkHUWBscBIJyJsdYbObe1DgxOhWoxYz3i4cft5iL3IpsaELdo5ES3LVJP
0kKh0FyFI2HTqRjNPWBWgQZyKX2uh0zoOhVApNdhQBl3mXZmaSuETsMzwdvewHOLOKp1tB1gCgvRXNf4OQ4XLOnSk6ksYW7Pd0NXEwhmFpgXTtQuJdDYXUwQD73oqq56ug6yX44MuscfdtDwJvuioBgkeItWcR
FygHmLkHFNeIloqMU0nxTeUoaoA4yzyPybiQTjSU0e9CgCxkODc1ynQGIFCzo6XUws5mz31LIDmGssFT4tqxgeDH9aCjHnWTcIMB46i2JEOonXfqOsCKrvvoJBlslQvilNPitcwOIgbmRUv0iOfWXb7EOmutFA
ZSs3Oeo5DGB1lkxRdZgidkV5fyfabYhR1Rd7jZsK7Sr4nzSSpnwuHjGRzqNd4Nwvi2Y94q6OuA17PVtwvordaJraTbCtOdkbCZPU7UsJfwlSOCCJM5XFmvIvquDTlyeNcaFypnADkEKcspqIqfxmECH9uH6H9I
CfQ5xeOzf1Cl1TqsDnWWQWmyrerFAu5IAaCmILWUaZwQTMHkI2vteeh9eigYjWEak23vD9DkGCB8KBfzVzHsIN0fidBEsGqE7wXg1CZWfLhRqu50WD676dKP61mVBeeyHRPyhtuZ7KLnETp0B9tYztzCe65pc9
lXyy1jjLGdMIrJfKPiSLC4q9C2O5qyxJMscO8D2ZgEpZve144x"", RANGE(0,1000), {{KEY_1: 1, KEY_2: 2, KEY_3: 3, KEY_4: 4, KEY_5: 5, KEY_6: 6, KEY_7: 7, KEY_8: 8, KEY_9: 9,
KEY_10: 10, KEY_11: 11, KEY_12: 12, KEY_13: 13, KEY_14: 14, KEY_15: 15, KEY_16: 16, KEY_17: 17, KEY_18: 18, KEY_19: 19, KEY_20: 20, KEY_21: 21, KEY_22: 22,
KEY_23: 23, KEY_24: 24, KEY_25: 25, KEY_26: 26, KEY_27: 27, KEY_28: 28, KEY_29: 29, KEY_30: 30, KEY_31: 31, KEY_32: 32, KEY_33: 33, KEY_34: 34, KEY_35: 35,
KEY_36: 36, KEY_37: 37, KEY_38: 38, KEY_39: 39, KEY_40: 40, KEY_41: 41, KEY_42: 42, KEY_43: 43, KEY_44: 44, KEY_45: 45, KEY_46: 46, KEY_47: 47, KEY_48: 48,
KEY_49: 49, KEY_50: 50, KEY_51: 51, KEY_52: 52, KEY_53: 53, KEY_54: 54, KEY_55: 55, KEY_56: 56, KEY_57: 57, KEY_58: 58, KEY_59: 59, KEY_60: 60, KEY_61: 61,
KEY_62: 62, KEY_63: 63, KEY_64: 64, KEY_65: 65, KEY_66: 66, KEY_67: 67, KEY_68: 68, KEY_69: 69, KEY_70: 70, KEY_71: 71, KEY_72: 72, KEY_73: 73, KEY_74: 74,
KEY_75: 75, KEY_76: 76, KEY_77: 77, KEY_78: 78, KEY_79: 79, KEY_80: 80, KEY_81: 81, KEY_82: 82, KEY_83: 83, KEY_84: 84, KEY_85: 85, KEY_86: 86, KEY_87: 87,
KEY_88: 88, KEY_89: 89, KEY_90: 90, KEY_91: 91, KEY_92: 92, KEY_93: 93, KEY_94: 94, KEY_95: 95, KEY_96: 96, KEY_97: 97, KEY_98: 98, KEY_99: 99, KEY_100: 100}}";
static void Main(string[] args)
{
try
{
var timer = new Stopwatch();
foreach (var nrOfRecords in RecordCounts)
{
timer.Restart();
TestResult(nrOfRecords);
Console.WriteLine($"Sync: {nrOfRecords:D5} records fetched in {timer.Elapsed.TotalMilliseconds}");
}
foreach (var nrOfRecords in RecordCounts)
{
timer.Restart();
TestResultAsync(nrOfRecords).GetAwaiter().GetResult();
Console.WriteLine($"Async: {nrOfRecords:D5} records fetched in {timer.Elapsed.TotalMilliseconds}");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.WriteLine("Finished. Press enter to exit.");
Console.ReadLine();
}
private static IEnumerable<IRecord> TestResult(int n)
{
IEnumerable<IRecord> result = null;
using (var driver = GraphDatabase.Driver(BoltUrl, AuthTokens.Basic(BoltUsername, BoltPassword)))
{
var session = driver.Session();
try
{
var records =
session.Run(string.Format(BoltQuery, n));
result = records.ToList();
}
finally
{
session.Dispose();
}
}
return result;
}
private static async Task<IEnumerable<IRecord>> TestResultAsync(int n)
{
IEnumerable<IRecord> result = null;
using (var driver = GraphDatabase.Driver(BoltUrl, AuthTokens.Basic(BoltUsername, BoltPassword)))
{
var session = driver.Session();
try
{
var cursor =
await session.RunAsync(string.Format(BoltQuery, n));
result = await cursor.ToListAsync();
}
finally
{
session.Dispose();
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment