论坛首页 编程语言技术论坛

rails中opensessioninview(数据库链接是否在views层还开启)

浏览 7527 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-09-08  
daigong 写道
opensessioninview好像是hibernate的概念,我只是想形容一下这个问题:其实就是在视图层是否关闭数据库链接。

rails中将model传到views层
例如学生与课程关系:
students = Students.all

这个时候我还是可以再views层使用
students.each do |stu|
  stu.clazz.name
end


再views可以进行sql查询(也就是懒加载问题),如果views在传输过程中因为网络原因堵塞,会照成数据库链接没有及时释放。

问一下,我现在可以在views上使用这种查询,输出名字,也就是说明rails的数据库链接再views输出后才关闭,是不是意味着程序有可能出现数据库链接没有及时释放问题。


各位,- -# 不要投新手贴,这个问题好像在论坛中没有讨论....希望和大家讨论一下



找到了一个资料,给后来看到帖子的人看下:
http://hi.baidu.com/chancey/blog/item/9b5d480ace7f2c1495ca6bc3.html

proxy_buffering
syntax: proxy_buffering on|off
default: proxy_buffering on
context: http, server, location
This directive activate response buffering of the proxied server.
If buffering is activated, then nginx assumes the answer of the proxied server as fast as possible, preserving it in the buffer, assigned by directive proxy_buffer_size and proxy_buffers.
If the response can not all be placed in memory, then parts of it will be written to disk.
If buffering is switched off, then the response is synchronously transferred to client immediately as it is received.
nginx do not attempt to count entire answer of the proxied server, maximum size of data, which nginx can accept from the server it is assigned by directive proxy_buffer_size.
For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.

再次感谢 QuakeWang 的提示!
0 请登录后投票
   发表时间:2011-09-08  
QuakeWang 写道
lighttpd和nginx都有,apache我没有用过,不太清楚。


多谢! 
0 请登录后投票
   发表时间:2011-09-09  
opensessioninview
又不是万能的,只不过是中偷懒的方式而已。
并发访问的时候对于key的保护显然无法达到要求。
0 请登录后投票
   发表时间:2011-09-09  
jackra 写道
opensessioninview
又不是万能的,只不过是中偷懒的方式而已。
并发访问的时候对于key的保护显然无法达到要求。


没有明白是怎么回事,能帮忙举一个case么? 
0 请登录后投票
   发表时间:2011-09-12  
QuakeWang 写道
daigong 写道

java的问题也好 rails的问题也好,在views层保持数据库链接对于互联网应用将会是致命的(感谢中国的网络环境),

java也好,rails也好,网络问题都不是open session in view的问题,因为前端有web server,而后端的应用在完成view渲染以后,会直接将内容放入到web server buff中,用户网络再慢也不会拉长数据库链接的保持时间。


赞同QuickWang的认识。动态网页生成HTML是在Server端,操作完数据库之后释放;Server把HTML发送给Browser,这个不会再数据库操作了,网络延迟也不会影响之前数据库的释放。
0 请登录后投票
   发表时间:2011-09-13  
javafansmagic 写道
QuakeWang 写道
daigong 写道

java的问题也好 rails的问题也好,在views层保持数据库链接对于互联网应用将会是致命的(感谢中国的网络环境),

java也好,rails也好,网络问题都不是open session in view的问题,因为前端有web server,而后端的应用在完成view渲染以后,会直接将内容放入到web server buff中,用户网络再慢也不会拉长数据库链接的保持时间。


赞同QuickWang的认识。动态网页生成HTML是在Server端,操作完数据库之后释放;Server把HTML发送给Browser,这个不会再数据库操作了,网络延迟也不会影响之前数据库的释放。


恩,是的,我也这么认为,不过前提是需要再Tomcat或者cgi前面增加反向代理,不然的话页面使用保持数据库链接会出现这种问题
0 请登录后投票
   发表时间:2011-09-14  
daigong 写道
daigong 写道
opensessioninview好像是hibernate的概念,我只是想形容一下这个问题:其实就是在视图层是否关闭数据库链接。

rails中将model传到views层
例如学生与课程关系:
students = Students.all

这个时候我还是可以再views层使用
students.each do |stu|
  stu.clazz.name
end


再views可以进行sql查询(也就是懒加载问题),如果views在传输过程中因为网络原因堵塞,会照成数据库链接没有及时释放。

问一下,我现在可以在views上使用这种查询,输出名字,也就是说明rails的数据库链接再views输出后才关闭,是不是意味着程序有可能出现数据库链接没有及时释放问题。


各位,- -# 不要投新手贴,这个问题好像在论坛中没有讨论....希望和大家讨论一下



找到了一个资料,给后来看到帖子的人看下:
http://hi.baidu.com/chancey/blog/item/9b5d480ace7f2c1495ca6bc3.html

proxy_buffering
syntax: proxy_buffering on|off
default: proxy_buffering on
context: http, server, location
This directive activate response buffering of the proxied server.
If buffering is activated, then nginx assumes the answer of the proxied server as fast as possible, preserving it in the buffer, assigned by directive proxy_buffer_size and proxy_buffers.
If the response can not all be placed in memory, then parts of it will be written to disk.
If buffering is switched off, then the response is synchronously transferred to client immediately as it is received.
nginx do not attempt to count entire answer of the proxied server, maximum size of data, which nginx can accept from the server it is assigned by directive proxy_buffer_size.
For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.

再次感谢 QuakeWang 的提示!


看了下daigong发的链接,有些不解:默认proxy_buffering是on,也就是说Nginx是开启代理缓存的,但问题有他说的那么严重吗 IO消耗那么大?大部分时间应该是在内存中缓存,只有较大的文件才会写硬盘,IO不会那么夸张吧?
0 请登录后投票
   发表时间:2011-09-14  
javafansmagic 写道
daigong 写道
daigong 写道
opensessioninview好像是hibernate的概念,我只是想形容一下这个问题:其实就是在视图层是否关闭数据库链接。

rails中将model传到views层
例如学生与课程关系:
students = Students.all

这个时候我还是可以再views层使用
students.each do |stu|
  stu.clazz.name
end


再views可以进行sql查询(也就是懒加载问题),如果views在传输过程中因为网络原因堵塞,会照成数据库链接没有及时释放。

问一下,我现在可以在views上使用这种查询,输出名字,也就是说明rails的数据库链接再views输出后才关闭,是不是意味着程序有可能出现数据库链接没有及时释放问题。


各位,- -# 不要投新手贴,这个问题好像在论坛中没有讨论....希望和大家讨论一下



找到了一个资料,给后来看到帖子的人看下:
http://hi.baidu.com/chancey/blog/item/9b5d480ace7f2c1495ca6bc3.html

proxy_buffering
syntax: proxy_buffering on|off
default: proxy_buffering on
context: http, server, location
This directive activate response buffering of the proxied server.
If buffering is activated, then nginx assumes the answer of the proxied server as fast as possible, preserving it in the buffer, assigned by directive proxy_buffer_size and proxy_buffers.
If the response can not all be placed in memory, then parts of it will be written to disk.
If buffering is switched off, then the response is synchronously transferred to client immediately as it is received.
nginx do not attempt to count entire answer of the proxied server, maximum size of data, which nginx can accept from the server it is assigned by directive proxy_buffer_size.
For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.

再次感谢 QuakeWang 的提示!


看了下daigong发的链接,有些不解:默认proxy_buffering是on,也就是说Nginx是开启代理缓存的,但问题有他说的那么严重吗 IO消耗那么大?大部分时间应该是在内存中缓存,只有较大的文件才会写硬盘,IO不会那么夸张吧?


这个文章也是我从网上找到的,他的问题,我怀疑是页面输出的数据过大,或者说他使用nginx的版本buffer比较小(猜测。。实际项目中我也没遇到国nginx大io的问题   项目不太大)
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics