Xiao Jia
Xiao Jia

Reputation: 4259

Is it a good idea to write a gateway for PostgreSQL in Erlang?

I'm writing a web application in Erlang, and want to store my data to PostgreSQL.

There're two kinds of resources in my application. One kind is very important while the other one is not that important.

I want to gain maximum efficiency and came up with such an idea: write a gateway for PostgreSQL. The gateway is a gen_server, and business logic (BL) parts can talk to the gateway for storing resources.

What I'm expecting from this idea is less seconds per request, since most of the resources are less important ones. But I wonder if this is a good idea, or in other words, can I really get what I'm expecting?

Please answer according to your experience or some reliable "web search results". Thanks. :-)

Upvotes: 0

Views: 238

Answers (1)

Isac
Isac

Reputation: 2068

I can see two problems with your proposal:

  1. All messages sent to the gen_server gateway will be serialized (blocking or non-blocking)
  2. If the gen_server gateway process crashes, you will lose at least the messages in the process mailbox.

What I would do is to create a helper module (not a process) that will be responsible for the database interactions. This process would use a postgresql library that supports connection pool (so the calls to DB can have some parallelism).

If you wish to do non-blocking DB operations for the less important resources, just spawn a process to do the DB interaction and move on.

Some links to postgresql erlang libraries (I haven't used any):

Postgresql connection pooling in Erlang

http://zotonic.com/page/519/epgsql-postgresql-driver

Upvotes: 4

Related Questions