Comments (5)
@gholly Concatenating multiple SQL statements in a single query string should save several roundtrips between your nginx server and the mysqld server, and thus faster. You do not really need the transaction thing here for the batch mode to work.
from lua-resty-mysql.
@agentzh First,Thank you for your answer.If the stitching multiple sql statement to insert into a string , and if one insert statement insert fails, three tables will not be able to keep pace . Missing rollback function .
How to avoid this situation ?
from lua-resty-mysql.
I try to write like this:
local db,err = mysql:new()
local ok,err,errno,sqlstate = db:connect(dbconf)
if not ok then
ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
return
end
res, err, errno, sqlstate = db:query("insert sql1;insert sql2;insert sql3;")
if not res then
ngx.log(ngx.ERR, "bad result #", ": ", err, ": ", errno, ": ", sqlstate, ".")
return
end
local i=2
while err == "again" do
res, err, errno, sqlstate = db:read_result()
if not res then
ngx.log(ngx.ERR, "bad result #", i, ": ", err, ": ", errno, ": ", sqlstate, ".")
return
end
-- ngx.say("result #", i, ": ", cjson.encode(res))
i = i + 1
end
local ok, err = db:set_keepalive(10000, 1000)
if not ok then
ngx.log(ngx.ERR,"failed to set keepalive: ",err)
--ngx.exit(500)
end
But the performance of this is stilll low:
What methods should be used to ensure that the table can be synchronized, and high performance?
from lua-resty-mysql.
@gholly Before optimizing anything, you should determine the bottleneck first. If you cannot max out your nginx worker processes's CPU usage to 100% then your mysqld server is the bottleneck. Otherwise, you can use the on-CPU flame graph tools (both on C land and Lua land) to determine the bottlenecks of the nginx server. See
http://openresty.org/en/profiling.html
BTW, it's recommended to move such general discussions to the openresty-en mailing list. This place is preserved for bug reports and development discussions. Thank you for your cooperation. Please see
http://openresty.org/en/community.html
from lua-resty-mysql.
@agentzh Well, first of all thank you for your advice, I try to use the on-CPU flame graph tools to maxout the nginx worker processes's CPU usage to higher.
I'll move to the question later openresty-en mailing list.
from lua-resty-mysql.
Related Issues (20)
- TODO: support specify pool_size and backlog in connect method. HOT 1
- create_db, create_user, grant and switch_user
- _recv_packet 函数 遇到错误返回,read_result并没有设置mysql. state=1 而是直接返回nil,导致下一次query失败 HOT 5
- lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:571: bad request
- 腾讯云服务器上mysql,使用lua不能访问数据库 HOT 2
- 为什么查询结果不支持返回number类型,而是将number类型也按string类型返回?
- Hardcoded query works but API disabled in the current context when using a variable HOT 3
- world.sql.gz page was not found, resulting in a CI error HOT 5
- schedule for SQL prepare statement support
- /usr/local/openresty/lualib/resty/mysql.lua:373: attempt to perform arithmetic on field 'packet_no' (a nil value)
- mysql查询是否串行 HOT 1
- bad result: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
- install by luarocks error HOT 3
- can not use "not res" to judge if the 'res' is empty table
- The connect function is thrown incorrectly
- using lua-resty-mysql query table contents, returned body incorrect
- connect() to unix:/var/lib/mysql/mysql.sock failed (11: Resource temporarily unavailable)
- Client does not support authentication protocol requested by server; consider upgrading MySQL client: 1251 08004 HOT 1
- Test case failures on rhel 7.6 ppc64le platform HOT 1
- Connection pooling for php-fpm with nginx unix sockets and resty mysql HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-mysql.