zackattackz

zackattackz

Hello!

I am currently working on an implementation of an Ecto Adapter for XTDB v2.x. 2.x is not a production-ready version, but I just wanted to try to make this project as a way to learn more about Elixir and XTDB as well.

So first of course I would need to create a DB driver for Elixir. XTDB has an HTTP API so I figured I will implement the driver using that as the protocol.

To create a driver, it seems standard that you should implement the DBConnection.Connection behavior. I just have a few struggles with this.

1.) From looking at other DBConnection implementations (MyXQL, Postgrex), they all seem to implement their database-specific protocols via TCP. Then DBConnection is somehow able to keep these TCP connections alive (via pinging?). My question is, how would one implement a DBConnection for an HTTP based protocol, specifically for the ping callback. To my understanding, HTTP is stateless, so I don’t think there is a realistic way to implement ping for this. Should I just leave it undefined and force :idle_interval = 0? Which brings me to my next question…
2.) Is there anything to be gained from implementing DBConnection for an HTTP based protocol? The main value-gain from implementing DBConnection seems to be that it is able to pool and maintain open TCP connections. I don’t know if there are other benefits, but if this is not applicable to HTTP, then should I bother with implementing it in the first place?

Sorry if these are ill-informed questions, as my knowledge of network protocols is very low. Any advice is appreciated, thank you!

Showing Posts 1 to 5

al2o3cr

al2o3cr

There’s “keepalive” in HTTP/1.1 that lets a connection be used for multiple sequential requests.

You’d need to check if XTDB supports it, though.

The goal of connection pooling for this is largely around reducing the number of SSL handshakes required - every time a new connection is opened it takes a bunch of network round-trips and cryptographic calculations.

ruslandoga

ruslandoga

:wave: @zackattackz

I implemented an HTTP driver for ClickHouse and DBConnection was very useful.

  1. You can GET /status for handle_ping, it would probably be enough to keep the connection alive.

  2. In addition to pooling and keeping connections alive, DBConnection provides a way to make them re-connect with backoff in case things go bad.

Just make sure to use an HTTP client without a pool!

zackattackz

zackattackz OP

Interesting, I will need to see if it is supported. Thank you!

zackattackz

zackattackz OP

This is awesome, thank you!! I was looking into using Mint as well, so this is a huge help :smiley:

zackattackz

zackattackz OP

Looking more into this it seems that HTTP 1.1 keeps connections alive by default, so pinging some known endpoint periodically, like @ruslandoga does in their Clickhouse driver, should be enough to keep the connection alive.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews