{"id":15374202,"url":"https://github.com/moteus/lua-odbc-pool","last_synced_at":"2025-04-05T08:21:23.245Z","repository":{"id":13475555,"uuid":"16165651","full_name":"moteus/lua-odbc-pool","owner":"moteus","description":"ODBC connections pool","archived":false,"fork":false,"pushed_at":"2016-02-20T12:57:54.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T15:50:54.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moteus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-23T07:36:21.000Z","updated_at":"2019-07-18T20:13:44.000Z","dependencies_parsed_at":"2022-09-10T13:40:55.197Z","dependency_job_id":null,"html_url":"https://github.com/moteus/lua-odbc-pool","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-odbc-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-odbc-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-odbc-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moteus%2Flua-odbc-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moteus","download_url":"https://codeload.github.com/moteus/lua-odbc-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247307328,"owners_count":20917448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:57:41.566Z","updated_at":"2025-04-05T08:21:23.206Z","avatar_url":"https://github.com/moteus.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"lua-odbc-pool\n=============\n\nODBC connections pool\n\n[![Build Status](https://travis-ci.org/moteus/lua-odbc-pool.png?branch=master)](https://travis-ci.org/moteus/lua-odbc-pool)\n\nThis library allows use same ODBC connections from different threads/states.\nAlso this library supports asyncronus reconnection to database in separate thread.\nThis library based on [LUQ](https://github.com/moteus/lua-luq), [lzmq](https://github.com/moteus/lzmq), [lua-llthreads2](https://github.com/moteus/lua-llthreads2) and [lua-odbc](https://github.com/moteus/lua-odbc) libraries.\nNote. This library may does not work with original `lua-llthreads` library.\n\n\n##Usage\n\n``` Lua\n--\n-- Client thread\n--\n\nlocal odbcpool = require \"odbc.dba.pool\"\n\nlocal QUEUE_NAME = \"MYDB\"\n\nlocal cli = odbcpool.client(QUEUE_NAME)\n\ncli:acquire(function(cnn)\n  -- if this function raise error or return `false` then\n  -- connection will put to reconnection queue\n\n  print(cnn:first_value(\"select 'Hello, '\"), cnn:first_value(\"select 'world'\"))\n\n  -- assume driver supports `connected` option\n  return not not cnn:connected()\nend)\n```\n\n```Lua\n--\n-- Server thread\n--\n\nlocal odbc     = require \"odbc\"\nlocal odbcpool = require \"odbc.pool\"\n\nlocal QUEUE_NAME = \"MYDB\"\n\n-- Create client to work with odbc.pool\nlocal cli = odbcpool.client(QUEUE_NAME)\n\n-- Create and start reconnect work thread\n-- Here we specify connection options\nlocal rthread = odbcpool.reconnect_thread(cli, 'emptydb', 'TestUser', 'sql')\nrthread:start()\n\n\n-- Create ODBC connections and put them to reconnect queue\nlocal env = odbc.environment()\n\nlocal connections = {}\nfor i = 1, 3 do\n  local cnn = odbc.assert(env:connection())\n  connections[#connections+1] = cnn\n  cli:reconnect(cnn)\nend\n\n-- Here we wait until end of application.\n-- We just need keep alive `rthread`, `env` and `connections` variables\n\n-- Suppose we run this code in coroutine then we can just yield\n-- and main thread resume us when application should be closed\n\ncoroutine.yield()\n\n-- Now we can stop reconnect work thread\nrthread:stop()\n```\n\n###Benchmark\n\nYou can run benchmark tool form `test` dir.\n\n```\n$ lua bench_pool.lua -c 2 -t 20 -q 500 -d 10 -w 50\n```\n\nHere we allocate 2 connections and run 20 threads.\nEach thread call `acquire` method 500 times and do \nquery with avg duration 10 msec. Each acquire wait \nat most 50 msec. Benchmark do not call actually sql\nquery but do sleep to emulate it.\n\n**Result:**\n```\nInput data:\n  Connections         : 2\n  Threads             : 20\n  Total query         : 10000 (500 per thread)\n  Avg query duration  : 10[msec]\n  Max wait            : 50[msec]\nResult:\n  Elapsed time        : 43.45[sec]\n  Real query duration : 81.74[msec]\n  Fail                : 2416 (24.16%)\n```\n\nHere we see that 24% of call `acquire` fails with timeout.\nAnd wiait+execute of query take about 81 msec.\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/moteus/lua-odbc-pool/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoteus%2Flua-odbc-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoteus%2Flua-odbc-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoteus%2Flua-odbc-pool/lists"}