bgoosman

bgoosman

I got a very basic NIF working for KuzuDB: GitHub - bgoosmanviz/kuzu_nif: Adapting KuzuDB's Rust crate to Elixir using Rustler · GitHub.

KuzuDB is an embedded graph database, in the same sense sqlite is an embedded sql database.

Posting here in case anyone is interested in helping flesh it out. I don’t know Rust very well.

Showing Posts 1 to 10

iampeter

iampeter

Hi, great job with starting the project, @bgoosman :slight_smile:

I’m wondering what your plans are in regard to the repo’s future; thanks!

bgoosman

bgoosman OP

I think integrating it with the Explorer library would be nice. i.e. pass dataframes from Elixir to/from the NIF, to be loaded into kuzudb, or fetched from kuzudb. I tried without much success.

WDYT?

bgoosman

bgoosman OP

Thanks for reminding me about this. I just updated the kuzu crate from 0.6.0 to 0.7.0 and improved the Elixir unit test.

We can do some pretty useful things with just run_query, like create a kuzudb using COPY FROM commands.

bgoosman

bgoosman OP

Besides that, feature parity with the API.

iampeter

iampeter

Thanks for updating your repo @bgoosman . Yes passing dataframes would be a good idea.

I’m wondering how the BEAM process management maps onto Rust threads, i.e. can we achieve proper query concurrency using KuzuDB via Elixir?

Are you using KuzuDB in production with your integration? What is the use case, without getting into any trade secrets :wink:

bgoosman

bgoosman OP

Not sure about BEAM & Rust threads. Here’s KuzuDB’s concurrency model https://docs.kuzudb.com/concurrency.

You got me thinking about the connection to the db. Right now run_query will create a new connection every time it’s called, which doesn’t sound ideal. I wonder how to manage a persistent connection.

bgoosman

bgoosman OP

We’re a graph viz company, so having an embeddable graph engine like KuzuDB would be an excellent improvement over a server based graph engine like Neo4j.

iampeter

iampeter

That’s my goal as well - being able to do in-mem Cypher queries.

iampeter

iampeter

Maybe @filmor @hansihe or @evnu could point us in the right direction in terms of how the mapping between BEAM processes and threads in Rust works.

ruslandoga

ruslandoga

:wave:

I was curious so I took a peek, and I think this function might benefit from being scheduled on a dirty scheduler: kuzu_nif/native/kuzu_ex/src/lib.rs at f94c2e243983650db26c4b19bb0f73835fd52ec5 · bgoosmanviz/kuzu_nif · GitHub and re: “mapping processes to threads”, I think usually libraries for wrappers around embedded databases create a NIF resource per database connection and then Elixir / Erlang manage them however they want, no 3rd-party threads involved. Looking at kuzu_nif/native/kuzu_ex/src/lib.rs at f94c2e243983650db26c4b19bb0f73835fd52ec5 · bgoosmanviz/kuzu_nif · GitHub, it seems like the API might be similar to DuckDB wrappers, since they also have a notion of “databases” and “connections” (SQLite only has “databases”). Two example DuckDB wrappers in Elixir:

So I think the API could be:

# NIF resource, DB is closed when the underlying reference refcount goes to 0
# can be a Dirty IO NIF
db = Kuzu.open() 

conns =
  for _ <- 1..:erlang.system_info(:dirty_io_schedulers) do
    # also NIF resources, since Kuzu is C++
    # they probably reference and keep DB alive too,
    # so it's easy to just wrap them info resources individually.
    # When none of them are referenced anymore, Erlang would "garbage collect"
    # them and call NIF resource destructors, which would destroy Kuzu connections.
    # once Kuzu connections are destroyed, Kuzu would probably close DB as well
    # since it would no longer be referenced either.
    # can be a Dirty CPU NIF or a plain NIF, depending on what Kuzu does here
    Kuzu.connect(db)
  end

{:ok, pool} = GenServer.start_link(SomePool, conns)
{ref, conn} = GenServer.call(pool, :checkout)

result =
  try do
    # since it might trigger disk access, it would be safer if it was a Dirty IO NIF
    Kuzu.query(conn, query)
    # or it can be a Kuzu.prepare followed by a Kuzu.execute
    # this would allow statement caching and query params
    # Kuzu.prepare can be a Dirty CPU or a plain NIF
    # Kuzu.execute would be a Dirty IO NIF for the same reasons as Kuzu.query
  after
    GenServer.cast(pool, {:checkin, ref, conn})
  end

# can probably be a plain NIF
Kuzu.to_arrow(result)

I think this would be useful in the upcoming AoC :slight_smile:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews