Comparison of -short benchmarks in cayley.
$ benchcmp pointer.bench concrete.bench
benchmark old ns/op new ns/op delta
BenchmarkNamePredicate 1673276 1655093 -1.09%
BenchmarkLargeSetsNoIntersection 318985907 261499984 -18.02%
BenchmarkNetAndSpeed 104403743 41516981 -60.23%
BenchmarkKeanuAndNet 17309258 16857513 -2.61%
BenchmarkKeanuAndSpeed 20159161 19282833 -4.35%
Comparison of pathological cases are not so happy.
benchmark old ns/op new ns/op delta
BenchmarkVeryLargeSetsSmallIntersection 55269775527 246084606672 +345.24%
BenchmarkHelplessContainsChecker 23436501319 24308906949 +3.72%
Profiling the worst case:
Pointer:
Total: 6121 samples
1973 32.2% 32.2% 1973 32.2% runtime.findfunc
773 12.6% 44.9% 773 12.6% readvarint
510 8.3% 53.2% 511 8.3% step
409 6.7% 59.9% 410 6.7% runtime.gentraceback
390 6.4% 66.2% 391 6.4% pcvalue
215 3.5% 69.8% 215 3.5% runtime.funcdata
181 3.0% 72.7% 181 3.0% checkframecopy
118 1.9% 74.6% 119 1.9% runtime.funcspdelta
96 1.6% 76.2% 96 1.6% runtime.topofstack
76 1.2% 77.5% 76 1.2% scanblock
Concrete:
Total: 25027 samples
9437 37.7% 37.7% 9437 37.7% runtime.findfunc
3853 15.4% 53.1% 3853 15.4% readvarint
2366 9.5% 62.6% 2366 9.5% step
2186 8.7% 71.3% 2186 8.7% runtime.gentraceback
1816 7.3% 78.5% 1816 7.3% pcvalue
1016 4.1% 82.6% 1016 4.1% runtime.funcdata
859 3.4% 86.0% 859 3.4% checkframecopy
506 2.0% 88.1% 506 2.0% runtime.funcspdelta
410 1.6% 89.7% 410 1.6% runtime.topofstack
303 1.2% 90.9% 303 1.2% runtime.newstack
|
||
|---|---|---|
| config | ||
| db | ||
| docs | ||
| graph | ||
| http | ||
| quad | ||
| query | ||
| static | ||
| svg | ||
| templates | ||
| .gitignore | ||
| .goxc.json | ||
| .travis.yml | ||
| 30kmoviedata.nq.gz | ||
| app.yaml | ||
| appengine.go | ||
| AUTHORS | ||
| cayley.cfg.example | ||
| cayley.go | ||
| cayley_appengine.cfg | ||
| cayley_test.go | ||
| CONTRIBUTING.md | ||
| CONTRIBUTORS | ||
| LICENSE | ||
| README.md | ||
| testdata.nq | ||
| TODO.md | ||
Its goal is to be a part of the developer's toolbox where Linked Data and graph-shaped data (semantic webs, social networks, etc) in general are concerned.
What's new?
- 2014-07-12:
- Massive cleanup and restructuring is largely done, it should be even easier to add to Cayley. (thanks @kortschak)
- A couple new backends are in progress, namely Postgres and Cassandra -- PRs when they come around.
- Cayley is now in Homebrew, thanks to @whitlockjc
- Our first client API (for Clojure, thanks to @wjb) -- list is now started on the Client API wiki page
Features
- Written in Go
- Easy to get running (3 or 4 commands, below)
- RESTful API
- or a REPL if you prefer
- Built-in query editor and visualizer
- Multiple query languages:
- Plays well with multiple backend stores:
- Modular design; easy to extend with new languages and backends
- Good test coverage
- Speed, where possible.
Rough performance testing shows that, on consumer hardware and an average disk, 134m triples in LevelDB is no problem and a multi-hop intersection query -- films starring X and Y -- takes ~150ms.
* Note that while it's not exactly Gremlin, it certainly takes inspiration from that API. For this flavor, see the documentation.
Getting Started
Grab the latest release binary and extract it wherever you like.
If you prefer to build from source, see the documentation on the wiki at How to start hacking on Cayley
cd to the directory and give it a quick test with:
./cayley repl --dbpath=testdata.nt
You should see a cayley> REPL prompt. Go ahead and give it a try:
// Simple math
cayley> 2 + 2
// JavaScript syntax
cayley> x = 2 * 8
cayley> x
// See all the entities in this small follow graph.
cayley> graph.Vertex().All()
// See only dani.
cayley> graph.Vertex("dani").All()
// See who dani follows.
cayley> graph.Vertex("dani").Out("follows").All()
Sample Data
For somewhat more interesting data, a sample of 30k movies from Freebase comes in the checkout.
./cayley repl --dbpath=30kmoviedata.nq.gz
To run the web frontend, replace the "repl" command with "http"
./cayley http --dbpath=30kmoviedata.nq.gz
And visit port 64210 on your machine, commonly http://localhost:64210
Running queries
The default environment is based on Gremlin and is simply a JavaScript environment. If you can write jQuery, you can query a graph.
You'll notice we have a special object, graph or g, which is how you can interact with the graph.
The simplest query is merely to return a single vertex. Using the 30kmoviedata.nq dataset from above, let's walk through some simple queries:
// Query all vertices in the graph, limit to the first 5 vertices found.
graph.Vertex().GetLimit(5)
// Start with only one vertex, the literal name "Humphrey Bogart", and retrieve all of them.
graph.Vertex("Humphrey Bogart").All()
// `g` and `V` are synonyms for `graph` and `Vertex` respectively, as they are quite common.
g.V("Humphrey Bogart").All()
// "Humphrey Bogart" is a name, but not an entity. Let's find the entities with this name in our dataset.
// Follow links that are pointing In to our "Humphrey Bogart" node with the predicate "name".
g.V("Humphrey Bogart").In("name").All()
// Notice that "name" is a generic predicate in our dataset.
// Starting with a movie gives a similar effect.
g.V("Casablanca").In("name").All()
// Relatedly, we can ask the reverse; all ids with the name "Casablanca"
g.V().Has("name", "Casablanca").All()
You may start to notice a pattern here: with Gremlin, the query lines tend to:
Start somewhere in the graph | Follow a path | Run the query with "All" or "GetLimit"
g.V("Casablanca") | .In("name") | .All()
And these pipelines continue...
// Let's get the list of actors in the film
g.V().Has("name","Casablanca")
.Out("/film/film/starring").Out("/film/performance/actor")
.Out("name").All()
// But this is starting to get long. Let's use a morphism -- a pre-defined path stored in a variable -- as our linkage
var filmToActor = g.Morphism().Out("/film/film/starring").Out("/film/performance/actor")
g.V().Has("name", "Casablanca").Follow(filmToActor).Out("name").All()
There's more in the JavaScript API Documentation, but that should give you a feel for how to walk around the graph.
Disclaimer
Not a Google project, but created and maintained by a Googler, with permission from and assignment to Google, under the Apache License, version 2.0.
Contact
- Email list: cayley-users at Google Groups
- Twitter: @cayleygraph
- IRC: #cayley on Freenode
