Tag: grape

为什么ActionDispatch :: Routing :: RouteSet需要这么长时间

我在Rails 4.2.1上使用Grape为我们的应用程序提供API。 但是当我今天检查Newrelic的性能时,我发现RackApp Proc#call和Grape API::Root#call占用了大量的时间。 (见截图) 然后我尝试使用rack_timer记录中间件中消耗的时间,发现ActionDispatch::Routing::RouteSet占用了大部分时间: Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 67.12579727172852 ms Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 101.51457786560059 ms Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 84.18059349060059 ms Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 1236.2565994262695 ms Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 8.124351501464844 ms Rack Timer (Application Action) — ActionDispatch::Routing::RouteSet: 55.65309524536133 ms […]

为什么在Rails中安装路由会因“未初始化的常量API”而失败?

我正在开发一个包含使用grapegem的API的应用程序。 这是我的Root类: module API class Root “text/error” } ).finish end prefix “api” version ‘v1’, using: :path format :json error_format :json mount ::API::ServiceRequests end end 这是我如何在路线中安装它: mount API::Root => ‘/’ 我收到的错误是: routes.rb:45:in块中的’:uninitialized constant API(NameError)` 这些文件的结构类似于app/api/root.rb ,我在application.rb有一些代码可以加载到文件中: config.paths.add File.join(‘app’, ‘api’), glob: File.join(‘**’, ‘*.rb’) config.autoload_paths += Dir[Rails.root.join(‘app’, ‘api’, ‘*’)]