public GraphDSREST_Output(IGraphDS myGraphDS, String myServerID, Dictionary<String, IOInterface> myPlugins) { _Plugins = myPlugins; _ServerID = myServerID; _ErrorMsg = new GraphDSREST_Errors(_ServerID); _GraphDS = myGraphDS; }
public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine) { var transactionID = myGraphDS.BeginTransaction(null); var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType("City"), (stats, vType) => vType); var inCountryProperty = vertexType.GetOutgoingEdgeDefinition("InCountry"); var nameProperty = vertexType.GetPropertyDefinition("Name"); List<double> timeForCityCountryTraversal = new List<double>(); for (int i = 0; i < myIterations; i++) { Stopwatch sw = Stopwatch.StartNew(); foreach (var aCity in myGraphDS.GetVertices<IEnumerable<IVertex>>(null, transactionID, new RequestGetVertices("City"), (stats, v) => v)) { var UK_Vertex = aCity.GetOutgoingSingleEdge(inCountryProperty.ID).GetTargetVertex(); } sw.Stop(); timeForCityCountryTraversal.Add(sw.Elapsed.TotalMilliseconds); } myGraphDS.CommitTransaction(null, transactionID); String result = GenerateTable(timeForCityCountryTraversal) + Environment.NewLine + String.Format("Average: {0}ms Median: {1}ms StandardDeviation {2}ms ", Statistics.Average(timeForCityCountryTraversal), Statistics.Median(timeForCityCountryTraversal), Statistics.StandardDeviation(timeForCityCountryTraversal)); Console.WriteLine(result); MyWriteLine(result); }
public void StartService(String myServiceName, IDictionary <string, object> myParameter) { IService Service = null; if (!_graphDSServices.TryGetValue(myServiceName, out Service)) { try { IGraphDS GraphDS = this as IGraphDS; Dictionary <string, object> Parameter = new Dictionary <string, object>(); Parameter.Add("GraphDS", GraphDS); Service = _pluginManager.GetAndInitializePlugin <IService>(myServiceName, Parameter); } catch (Exception Ex) { throw new ServiceException("An error occured when trying to initialize " + myServiceName + "!" + Environment.NewLine + "See inner exception for details.", Ex); } _graphDSServices.Add(Service.PluginName, Service); } try { Service.Start(myParameter); } catch (Exception Ex) { throw new ServiceException("An error occured when trying to start " + myServiceName + "!" + Environment.NewLine + "See inner exception for details.", Ex); } }
public sonesRPCServer(IGraphDS myGraphDS, IPAddress myIPAdress, ushort myPort, String myURI, Boolean myIsSecure, Boolean myUseStreaming = false, Boolean myAutoStart = false, Boolean myIsSingleFile = false) { #if __MonoCS__ this.UseStreaming = false; #else this.UseStreaming = myUseStreaming; #endif this._GraphDS = myGraphDS; this.IsSecure = myIsSecure; this.ListeningIPAdress = myIPAdress; this.ListeningPort = myPort; this.IsSingleFile = myIsSingleFile; this.URI = new Uri((myIsSecure == true ? "https://" : "http://") + myIPAdress.ToString() + ":" + myPort + "/" + myURI); this.MexUri = new Uri("http://" + myIPAdress.ToString() + ":" + (myPort + 1) + "/" + myURI); if (!this.URI.IsWellFormedOriginalString()) throw new Exception("The URI Pattern is not well formed!"); InitializeServer(); if (myAutoStart) { StartServiceHost(); } }
public TagExample() { //Make a new GraphDB instance GraphDB = new SonesGraphDB(); #region Configure PlugIns // Plugins are loaded by the GraphDS with their according PluginDefinition and only if they are listed // below - there is no auto-discovery for plugin types in GraphDS (!) #region Query Languages // the GQL Query Language Plugin needs the GraphDB instance as a parameter List<PluginDefinition> QueryLanguages = new List<PluginDefinition>(); Dictionary<string, object> GQL_Parameters = new Dictionary<string, object>(); GQL_Parameters.Add("GraphDB", GraphDB); QueryLanguages.Add(new PluginDefinition("sones.gql", GQL_Parameters)); #endregion #endregion GraphDSPlugins PluginsAndParameters = new GraphDSPlugins(null, QueryLanguages); var credentials = new UserPasswordCredentials("User", "test"); GraphDSServer = new GraphDS_Server(GraphDB, (ushort)9975, "User", "test", IPAddress.Any, PluginsAndParameters); GraphDSServer.LogOn(credentials); //GraphDSServer.StartRESTService("", Properties.Settings.Default.ListeningPort, IPAddress.Any); //get a Security- and TransactionToken SecToken = GraphDSServer.LogOn(credentials); TransToken = GraphDSServer.BeginTransaction(SecToken); }
public GraphDSREST_Output(IGraphDS myGraphDS, String myServerID, Dictionary <String, IOInterface> myPlugins) { _Plugins = myPlugins; _ServerID = myServerID; _ErrorMsg = new GraphDSREST_Errors(_ServerID); _GraphDS = myGraphDS; }
public sonesRPCServer(IGraphDS myGraphDS, IPAddress myIPAdress, ushort myPort, String myURI, Boolean myIsSecure, Boolean myUseStreaming = false, Boolean myAutoStart = false, Boolean myIsSingleFile = false) { #if __MonoCS__ this.UseStreaming = false; #else this.UseStreaming = myUseStreaming; #endif this._GraphDS = myGraphDS; this.IsSecure = myIsSecure; this.ListeningIPAdress = myIPAdress; this.ListeningPort = myPort; this.IsSingleFile = myIsSingleFile; this.URI = new Uri((myIsSecure == true ? "https://" : "http://") + myIPAdress.ToString() + ":" + myPort + "/" + myURI); this.MexUri = new Uri("http://" + myIPAdress.ToString() + ":" + (myPort + 1) + "/" + myURI); if (!this.URI.IsWellFormedOriginalString()) { throw new Exception("The URI Pattern is not well formed!"); } InitializeServer(); if (myAutoStart) { StartServiceHost(); } }
public IPluginable InitializePlugin(string UniqueString, Dictionary <string, object> myParameters = null) { IGraphDS GraphDS = null; if (myParameters != null && myParameters.ContainsKey("GraphDS")) { GraphDS = (IGraphDS)myParameters["GraphDS"]; } return(new RESTService(GraphDS)); }
public void Init(ParsingContext context, ParseTreeNode parseNode, IGraphDS myGraphDS) { base.InitNode(context, parseNode, myGraphDS); _pluginManager.Discover(); _componentName = parseNode.ChildNodes[1].Token.ValueString; if (base.CheckForComponent<IBenchmark>(_componentName, context, parseNode.ChildNodes[1].Token.Location)) { if (parseNode.ChildNodes[2].ChildNodes.Count > 0) { try { _iterations = Convert.ToInt64(parseNode.ChildNodes[2].ChildNodes[2].Token.ValueString); } catch(Exception) { context.AddParserMessage(ParserErrorLevel.Error, parseNode.ChildNodes[2].ChildNodes[2].Token.Location, "This is not a valid iteration count"); return; } } Dictionary<String, String> options; if (parseNode.ChildNodes[3].ChildNodes.Count > 0) { options = ((OptionsNode)(parseNode.ChildNodes[3].AstNode)).Options; } else { options = new Dictionary<String, String>(); } _benchmark = _pluginManager.GetAndInitializePlugin<IBenchmark>( _componentName, base.PreparePluginOptions(options, _graphDS)); } }
public void Init(ParsingContext context, ParseTreeNode parseNode, IGraphDS myGraphDS) { base.InitNode(context, parseNode, myGraphDS); _pluginManager.Discover(); _componentName = parseNode.ChildNodes[1].Token.ValueString; if (base.CheckForComponent<IImport>(_componentName, context, parseNode.ChildNodes[1].Token.Location)) { Dictionary<String, String> options; if (parseNode.ChildNodes[2].ChildNodes.Count > 0) { options = ((OptionsNode)(parseNode.ChildNodes[2].AstNode)).Options; } else { options = new Dictionary<String, String>(); } _import = _pluginManager.GetAndInitializePlugin<IImport>( _componentName, base.PreparePluginOptions(options, _graphDS)); } }
public RESTService(IGraphDS myGraphDS) { _GraphDS = myGraphDS; _LifeTime = new Stopwatch(); }
public void Initialize(IGraphDS myGraphDS, ushort myPort, IPAddress myIPAddress) { _IGraphDS = myGraphDS; _ErrorMsg = new GraphDSREST_Errors(_ServerID); _RESTOutput = new GraphDSREST_Output(myGraphDS, _ServerID, _IOPlugins); }
public void Init(ParsingContext context, ParseTreeNode parseNode, IGraphDS myGraphDS) { base.InitNode(context, parseNode, myGraphDS); }
public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine) { var transactionID = myGraphDS.BeginTransaction(null); var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType(_interestingVertexType), (stats, vType) => vType); var vertices = myGraphDS.GetVertices<IEnumerable<IVertex>>(null, transactionID, new RequestGetVertices(_interestingVertexType), (stats, v) => v); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < myIterations - 1; i++) { CountAllEdgesParallel(vertices); } var edgeCount = CountAllEdgesParallel(vertices); sw.Stop(); myGraphDS.CommitTransaction(null, transactionID); MyWriteLine(String.Format("Counted {0} edges.", edgeCount)); MyWriteLine(String.Format("Traversed {0} edges per second", edgeCount / (sw.Elapsed.TotalSeconds / myIterations))); }
long CreateANewUser(IVertexType usertype, long i, List<long> recentVertexIDs, Random myPRNG, IGraphDS myGraphDS, Int64 myTransactionID) { if (recentVertexIDs.Count == 0) { return myGraphDS.Insert<long>(null, myTransactionID, new RequestInsertVertex("User") .AddStructuredProperty("Name", "User" + i) .AddStructuredProperty("Age", myPRNG.Next(18, 90)), GetVertexID); } else { return myGraphDS.Insert<long>(null, myTransactionID, new RequestInsertVertex("User") .AddStructuredProperty("Name", "User" + i) .AddStructuredProperty("Age", myPRNG.Next(18, 90)) .AddEdge(CreateEdge(recentVertexIDs, myPRNG, usertype.ID)), GetVertexID); } }
public RPCServiceContract(IGraphDS myGraphDS) { this.GraphDS = myGraphDS; }
public RemoteAPIService(IGraphDS myGraphDS) { _RunningTime = new Stopwatch(); _GraphDS = myGraphDS; }
public void SocialNetwork(IGraphDS myGraphDS) { Random PRNG = new Random(); List<long> vertexIDs = new List<long>(); var transactionID = myGraphDS.BeginTransaction(null); //create the user type var usertype = myGraphDS.CreateVertexType<IVertexType>(null, transactionID, new RequestCreateVertexType( new VertexTypePredefinition("User") .AddProperty(new PropertyPredefinition("Name", "String")) .AddProperty(new PropertyPredefinition("Age", "Int32")) .AddIndex(new IndexPredefinition("MyAgeIndex").SetIndexType("sonesindex").AddProperty("Age").SetVertexType("User")) .AddOutgoingEdge(new OutgoingEdgePredefinition("Friends", "User").SetMultiplicityAsMultiEdge()) ), (stats, vType) => vType); Console.Write("Imported User: "); for (long i = 0; i < _countOfUsers; i++) { if (i % 1000 == 0) { String iString = i.ToString(); Console.Write(iString); Console.CursorLeft -= iString.Length; } vertexIDs.Add(CreateANewUser(usertype, i, vertexIDs, PRNG, myGraphDS, transactionID)); } }
public BenchmarkGrammar(IGraphDS myGraphDS, ushort myListeningPort, string myUsername, string myPassword) : base(false) { #region data _graphDS = myGraphDS; #endregion #region grammar #region Terminals var numberLiteral = new NumberLiteral("number", NumberOptions.AllowSign | NumberOptions.DisableQuickParse); var stringLiteral = new StringLiteral("string", "'", StringOptions.AllowsDoubledQuote | StringOptions.AllowsLineBreak); var identifier = new IdentifierTerminal("identifier", "ÄÖÜäöüß0123456789_", "ÄÖÜäöü0123456789$_"); var S_IMPORT = ToTerm("IMPORT"); var S_BENCHMARK = ToTerm("BENCHMARK"); var S_ITERATIONS = ToTerm("ITERATIONS"); var S_EQUALS = ToTerm("="); var S_TRUE = ToTerm("TRUE"); var S_FALSE = ToTerm("FALSE"); var S_OPTIONS = ToTerm("OPTIONS"); var S_BRACKETLEFT = ToTerm("("); var S_BRACKETRIGHT = ToTerm(")"); var S_COMMA = ToTerm(","); var S_CLEAR = ToTerm("CLEAR"); var S_LIST = ToTerm("LIST"); #endregion #region Non-terminals var NT_options = new NonTerminal("Options", CreateOptionsNode); var NT_KeyValueList = new NonTerminal("ValueList", CreateKeyValueListNode); var NT_KeyValuePair = new NonTerminal("KeyValuePair", CreateKeyValuePairNode); var NT_BooleanVal = new NonTerminal("BooleanVal"); var NT_iterations = new NonTerminal("Iterations"); var NT_import = new NonTerminal("Import", CreateImportNode); var NT_clear = new NonTerminal("Clear", CreateClearNode); var NT_benchmark = new NonTerminal("Benchmark", CreateBenchmarkNode); var NT_list = new NonTerminal("List", CreateListNode); var NT_Stmt = new NonTerminal("Stmt", CreateStatementNode); #endregion #region BNF rules NT_BooleanVal.Rule = S_TRUE | S_FALSE; NT_KeyValuePair.Rule = identifier + S_EQUALS + stringLiteral | identifier + S_EQUALS + numberLiteral | identifier + S_EQUALS + NT_BooleanVal; NT_KeyValueList.Rule = MakePlusRule(NT_KeyValueList, S_COMMA, NT_KeyValuePair); NT_options.Rule = Empty | S_OPTIONS + S_BRACKETLEFT + NT_KeyValueList + S_BRACKETRIGHT; NT_Stmt.Rule = NT_import | NT_benchmark | NT_clear | NT_list; NT_iterations.Rule = Empty | S_ITERATIONS + S_EQUALS + numberLiteral; NT_import.Rule = S_IMPORT + stringLiteral + NT_options; NT_clear.Rule = S_CLEAR; NT_list.Rule = S_LIST; NT_benchmark.Rule = S_BENCHMARK + stringLiteral + NT_iterations + NT_options; this.Root = NT_Stmt; // Set grammar root #endregion #region Token filter //we need to add continuation symbol to NonGrammarTerminals because it is not used anywhere in grammar NonGrammarTerminals.Add(ToTerm(@"\")); #endregion #region Initialize console attributes DiscordianDate ddate = new DiscordianDate(); ConsoleTitle = "sones GraphDB Benchmark Console"; ConsoleGreeting = @" sones GraphDB version 2.0 - " +ddate.ToString() + @" (C) sones GmbH 2007-2011 - http://www.sones.com ----------------------------------------------- This GraphDB Instance offers the following options: * REST Service is started at http://localhost:" + myListeningPort + @" * access it directly by passing the GraphQL query using the REST interface or a client library. (see documentation) * if you want JSON Output add ACCEPT: application/json to the client request header (or application/xml or application/text) * we recommend to use the AJAX WebShell. Browse to http://localhost:" + myListeningPort + @"/WebShell and use the username """ + myUsername+ @""" and password """+ myPassword + @""" * Benchmark commands are: * IMPORT 'importPluginName' [key = value [, key = value]] * BENCHMARK 'benchmarkPluginName' ITERATIONS = countOfIterations [key = value [, key = value]] * CLEAR * LIST Press Ctrl-C to exit the program at any time. "; ConsolePrompt = "Benchmark> "; ConsolePromptMoreInput = "..."; #endregion this.LanguageFlags = LanguageFlags.CreateAst | LanguageFlags.CanRunSample; MarkPunctuation(S_BRACKETLEFT.ToString(), S_BRACKETRIGHT.ToString()); #endregion }
public void SocialNetwork(IGraphDS myGraphDS) { var transactionID = myGraphDS.BeginTransaction(null); #region ontology [API] var entityTypeDefinition = new VertexTypePredefinition(_vtEntity) .AddProperty(new PropertyPredefinition(_pName, typeof(String).Name)); var userTypeDefinition = new VertexTypePredefinition(_vtUser) .SetSuperTypeName(_vtEntity) .AddOutgoingEdge(new OutgoingEdgePredefinition(_pHasVisited, _vtCity).SetMultiplicityAsMultiEdge()); var placeTypeDefinition = new VertexTypePredefinition(_vtPlace) .SetSuperTypeName(_vtEntity); var countryTypeDefinition = new VertexTypePredefinition(_vtCountry) .SetSuperTypeName(_vtPlace) .AddIncomingEdge(new IncomingEdgePredefinition(_pCities, _vtCity, _pInCountry)); var cityTypeDefinition = new VertexTypePredefinition(_vtCity) .SetSuperTypeName(_vtPlace) .AddOutgoingEdge(new OutgoingEdgePredefinition(_pInCountry, _vtCountry)); Dictionary<String, IVertexType> vertexTypes = myGraphDS.CreateVertexTypes(null, transactionID, new RequestCreateVertexTypes(new List<VertexTypePredefinition> { entityTypeDefinition, userTypeDefinition, placeTypeDefinition, countryTypeDefinition, cityTypeDefinition }), (stats, types) => types.ToDictionary(vType => vType.Name, vType => vType)); #endregion #region country [GQL] ExecuteQuery("insert into " + _vtCountry + " values ( " + _pName + " = 'UK' )", myGraphDS, transactionID); #endregion #region cities [GQL] var cityVertexIDs = new List<long>(); foreach (var aCity in new List<String> { "London", "Manchester", "Edinburgh", "Cambridge", "Oxford" }) { cityVertexIDs.Add(ExecuteQuery("insert into " + _vtCity + " values ( " + _pName + " = '" + aCity + "', " + _pInCountry + " = REF(" + _pName + " = 'UK'))", myGraphDS, transactionID).First().GetProperty<long>("VertexID")); } #endregion #region user [API] var userType = vertexTypes[_vtUser]; var cityType = vertexTypes[_vtCity]; Parallel.ForEach( Partitioner.Create(0, _countOfUsers, _countOfUsers / Environment.ProcessorCount), range => { for (long i = range.Item1; i < range.Item2; i++) { CreateANewUser(userType, i, myGraphDS, cityVertexIDs, cityType, transactionID); } }); #endregion myGraphDS.CommitTransaction(null, transactionID); }
public void Execute(sones.GraphDBBenchmark.Converter.WriteLineToConsole MyWriteLine, IGraphDS myGraphDS) { SocialNetwork(myGraphDS); }
Int64 CountAllEdgesParallelPartitioner(IVertexType usertype, IGraphDS myGraphDB, List<IVertex> vertices) { object lockObject = new object(); Int64 edgeCount = 0L; var rangePartitioner = Partitioner.Create(0, vertices.Count); Parallel.ForEach( rangePartitioner, () => 0L, (range, loopstate, initialValue) => { Int64 localCount = initialValue; for (int i = range.Item1; i < range.Item2; i++) { foreach (var aOutGoingEdge in vertices[i].GetAllOutgoingHyperEdges()) { foreach (var aInnerVertex in aOutGoingEdge.Item2.GetTargetVertices()) { localCount++; } } } return localCount; }, (localSum) => { lock (lockObject) { edgeCount += localSum; } }); return edgeCount; }
public QueryResult ExecuteQuery(string myQuery, IGraphDS myGraphDS, Int64 transactionID) { return myGraphDS.Query(null, transactionID, myQuery, "sones.gql"); }
public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine) { var transactionID = myGraphDS.BeginTransaction(null); var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType(_interestingVertexType), (stats, vType) => vType); var vertexList = myGraphDS.GetVertices<List<IVertex>>(null, transactionID, new RequestGetVertices(_interestingVertexType), (stats, vertices) => vertices.ToList()); List<double> tps = new List<double>(); long edgeCount= 0; for (int i = 0; i < myIterations; i++) { Stopwatch sw = Stopwatch.StartNew(); edgeCount = CountAllEdgesParallelPartitioner(vertexType, myGraphDS, vertexList); sw.Stop(); tps.Add(edgeCount / sw.Elapsed.TotalSeconds); } myGraphDS.CommitTransaction(null, transactionID); MyWriteLine(String.Format("Traversed {0} edges.", edgeCount)); MyWriteLine(String.Format("Traversed {0} edges. Average: {1}TPS Median: {2}TPS StandardDeviation {3}TPS ", edgeCount, Statistics.Average(tps), Statistics.Median(tps), Statistics.StandardDeviation(tps))); }
void CreateANewUser(IVertexType myUsertype, long myCounter, IGraphDS myGraphDS, List<long> myCityVertexIDs, IVertexType myCityType, Int64 myTransactionID) { myGraphDS.Insert<long>(null, myTransactionID, new RequestInsertVertex(_vtUser) .AddStructuredProperty(_pName, "User" + myCounter) .AddEdge(new EdgePredefinition(_pHasVisited).AddVertexID(_vtCity, myCityVertexIDs)), GetVertexID); }