Home
Wade Ruby
Cancel

Ruby 使用rack Mini Profiler来分析和优化rails

参考 : https://github.com/MiniProfiler/rack-mini-profiler 以及: 这个: 特别有意思, 写的特别好:  https://stackify.com/rack-mini-profiler-a-complete-guide-on-rails-performance/ 1. Gemfile: gem 'rack-mini-...

Ruby Profiler Memory_profiler查看rubyrails项目的内存使用情况

memory_profilerhttps://www.rubydoc.info/gems/memory_profiler/1.0.0 功能超级强大,还没使用。 Gemfile:  gem 'memory_profiler' 基本用法: 仅作用于rb脚本: ruby-memory-profiler [options] <script.rb> 或者这样: require...

Ruby 几个图文并茂的profiler工具

参考 https://scoutapm.com/blog/which-rails-profiler-is-right-for-you

Rails 超级重要!rubyorrailsprofiler Derailed_benchmarks:查看项目的内存

https://github.com/schneems/derailed_benchmarks 列出rails项目的静态内存(未运行时,仅查看某些gem占用的空间)和运行时内存(这个是我期望的) README写的特别好

Ruby Memory_profiling的使用,rails下面。

参考 https://gist.github.com/os6sense/35b9e37eb8f23bdb4a81cde1cc23aa03 add to gemfile : gem 'memory_profiler', require: true, github: 'SamSaffron/memory_profiler' Add a config/initializer/me...

Ruby 使用ruby Prof,很类似jprofiler的软件

https://github.com/ruby-prof/ruby-prof

Linux 使用graphviz来查看某些报表和图形(ruby优化使用rubyprofiler)

参考:https://www.graphviz.org/download/ ubuntu安装方式: apt-get install graphvz  使用方式: dot ~/Downloads/primes.dot -Tpng -o test.png dot 是命令 ~/Downloads/primes.dot 是 dot源文件 -Tpng 表示生成的图片文件格式 test.png...

Ruby 使用rbtrace来观察rubyrails的内存情况,判断内存泄漏memoryleaks

参考: https://github.com/tmm1/rbtrace

Rails 使用多数据库multipledatabases

这个超级简单。 Rails4 中需要参考:  https://stackoverflow.com/questions/28485137/multiple-database-connection-in-rails-4/28490913 1. config/database.yml 中,增加第二个数据库配置 second_production: ... 2.  在对应的mo...

Ruby 使用newrelic来判断rails应用的问题

new relic: https://rpm.newrelic.com/accounts/51021/applications/setup#ruby 1. 正常注册(进入账户后,居然还看到了我N年前做的项目) 2. 新建。 选择ruby, 等等一系列,跟 oneapm的一毛一样。

Ruby Sinatra的启动方式绝对不要用rackup,要用thinstart Rconfig.ru或者puma

我把文章发表在了: https://stackoverflow.com/questions/56422645/performance-of-classic-sinatra-and-modular-sinatra-am-i-doing-wrong 闹了个大乌龙:  1. wrong: $ ruby main.rb (based on rack?)2. wrong: $ rack...

Ruby Rails分页:willpaginate,对于大数据量,不要用@count,会引起加载缓慢,要使用without

前端erb 页面:  <%= link_to_prev_page @trades, "上一页" %><%= link_to_next_page @trades, "下一页" %> 后端controller:  调用.without_count 方法 @trades.page(params[:page]).per(1000).without_count

Ruby Sinatravsgrape框架比较

sinatra 和 grape都是ruby 的api框架。  性能上: sinatra大约是 grape的2倍。高判立下。 sinatra代码 require 'sinatra' get '/hi' do "Put this in your pipe & smoke it!, name: #{params[:name]}" end $ ab -n 1000 -c ...

Rails Kaminari在进行大表分页的解决办法:without_count

参考:  https://github.com/amatsuda/kaminari#paginating-without-issuing-select-count-query kaminari的 paginate 方法, 会对整个 result list 进行判断, 看看它的 count是多少.  对于表的记录特别大的时候,  (例如1个亿), 很耗时,大约几...

Ruby 使用oneapm来监控rails项目,做性能优化调试

参考:https://www.jianshu.com/p/6a0a0d20bc98 之前用过new relic, 两个点: 1.没有解决不了的问题 2.国外网络访问起来速度慢. 现在有需求了,发现了项目有内存泄漏. 所以选择使用oneapm 1. 注册 2. 选择 applications 监控 3. 点击下载 探针。 就会出现页面。  4. 下载yml文件到config 目录下...

Rails 保存csv

看下面的例子即可 需要注意的是,身份证号在csv中不带引号,所以Excel会把 > 15位的数字显示成 ### , 所以我们需要把它特殊处理一下 ,价格\t def download_csv require 'csv' # 这个是获得数据的方法 @members = get_members params headers = ['邮箱','电话','姓...

Rust 以?结尾的调用,跟rails中的try非常类似,为了更方便的处理异常

参考:https://doc.rust-lang.org/edition-guide/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html 我们看到,一些方法调用,会 用?结尾。 例如:  db.execute(xx)?;  这样的作用是...

Rails After_save与after_commit

https://ruby-china.org/topics/29503 after_save:   对于 update, create 都会用到。 但是如果 该block中的代码抛出异常, 那么 这个save 就会取消。  所以,如果希望block中的代码不会影响到 save等操作,就要用 after_commit

Ruby "\xe6"fromascii 8bittoutf的问题解决办法

今天早上遇到这个情况,我在提交一个最普通的查询form的时候, 报错。  这个一看就是rails 日志,在记录每个请求的时候,只要参数中有一些 对号  这样的东西,就会有问题。 /managements/members?utf8=✓&email=22&commit=查询 33 2019-05-07 07:25:49 +0800: Rack app err...

Rust 从jsrubyjava的入门手册

if 后面的条件不需要 圆括号 {} 是一个block , 例如 main 函数中,可以使用 多个 {}  没有三元表达式 使用cargo进行包管理, 类似gem , bundler, npm  变量的类型:  let xxx = 32    这里xxx默认是不可改变的  let mut x = 32;    这...