Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host.h

Issue 18541: Add a constraint on how many requests can be outstanding for any given render (browser-side). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/resource_dispatcher_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is the browser side of the resource dispatcher, it receives requests 5 // This is the browser side of the resource dispatcher, it receives requests
6 // from the RenderProcessHosts, and dispatches them to URLRequests. It then 6 // from the RenderProcessHosts, and dispatches them to URLRequests. It then
7 // fowards the messages from the URLRequests back to the correct process for 7 // fowards the messages from the URLRequests back to the correct process for
8 // handling. 8 // handling.
9 // 9 //
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 pending_data_count(0), 74 pending_data_count(0),
75 is_download(false), 75 is_download(false),
76 pause_count(0), 76 pause_count(0),
77 mixed_content(mixed_content), 77 mixed_content(mixed_content),
78 resource_type(resource_type), 78 resource_type(resource_type),
79 filter_policy(FilterPolicy::DONT_FILTER), 79 filter_policy(FilterPolicy::DONT_FILTER),
80 last_load_state(net::LOAD_STATE_IDLE), 80 last_load_state(net::LOAD_STATE_IDLE),
81 upload_size(upload_size), 81 upload_size(upload_size),
82 last_upload_position(0), 82 last_upload_position(0),
83 waiting_for_upload_progress_ack(false), 83 waiting_for_upload_progress_ack(false),
84 memory_cost(0),
84 is_paused(false), 85 is_paused(false),
85 has_started_reading(false), 86 has_started_reading(false),
86 paused_read_bytes(0) { 87 paused_read_bytes(0) {
87 } 88 }
88 89
89 // Top-level ResourceHandler servicing this request. 90 // Top-level ResourceHandler servicing this request.
90 scoped_refptr<ResourceHandler> resource_handler; 91 scoped_refptr<ResourceHandler> resource_handler;
91 92
92 // CrossSiteResourceHandler for this request, if it is a cross-site request. 93 // CrossSiteResourceHandler for this request, if it is a cross-site request.
93 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers 94 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 net::LoadState last_load_state; 129 net::LoadState last_load_state;
129 130
130 uint64 upload_size; 131 uint64 upload_size;
131 132
132 uint64 last_upload_position; 133 uint64 last_upload_position;
133 134
134 base::TimeTicks last_upload_ticks; 135 base::TimeTicks last_upload_ticks;
135 136
136 bool waiting_for_upload_progress_ack; 137 bool waiting_for_upload_progress_ack;
137 138
139 // The approximate in-memory size (bytes) that we credited this request
140 // as consuming in |outstanding_requests_memory_cost_map_|.
141 int memory_cost;
142
138 private: 143 private:
139 // Request is temporarily not handling network data. Should be used only 144 // Request is temporarily not handling network data. Should be used only
140 // by the ResourceDispatcherHost, not the event handlers. 145 // by the ResourceDispatcherHost, not the event handlers.
141 bool is_paused; 146 bool is_paused;
142 147
143 // Whether this request has started reading any bytes from the response 148 // Whether this request has started reading any bytes from the response
144 // yet. Will be true after the first (unpaused) call to Read. 149 // yet. Will be true after the first (unpaused) call to Read.
145 bool has_started_reading; 150 bool has_started_reading;
146 151
147 // How many bytes have been read while this request has been paused. 152 // How many bytes have been read while this request has been paused.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // case the caller should not send the data. 244 // case the caller should not send the data.
240 bool WillSendData(int render_process_host_id, int request_id); 245 bool WillSendData(int render_process_host_id, int request_id);
241 246
242 // Pauses or resumes network activity for a particular request. 247 // Pauses or resumes network activity for a particular request.
243 void PauseRequest(int render_process_host_id, int request_id, bool pause); 248 void PauseRequest(int render_process_host_id, int request_id, bool pause);
244 249
245 // Returns the number of pending requests. This is designed for the unittests 250 // Returns the number of pending requests. This is designed for the unittests
246 int pending_requests() const { 251 int pending_requests() const {
247 return static_cast<int>(pending_requests_.size()); 252 return static_cast<int>(pending_requests_.size());
248 } 253 }
254
255 // Intended for unit-tests only. Returns the memory cost of all the
256 // outstanding requests (pending and blocked) for |render_process_host_id|.
257 int GetOutstandingRequestsMemoryCost(int render_process_host_id) const;
258
259 // Used by unit-tests to override the max outstanding requests constraint.
260 void set_max_outstanding_requests_cost_per_process(int limit) {
261 max_outstanding_requests_cost_per_process_ = limit;
262 }
263
264 // The average private bytes increase of the browser for each new pending
265 // request. Experimentally obtained.
266 static const int kAvgBytesPerOutstandingRequest = 4400;
249 267
250 DownloadFileManager* download_file_manager() const { 268 DownloadFileManager* download_file_manager() const {
251 return download_file_manager_; 269 return download_file_manager_;
252 } 270 }
253 271
254 DownloadRequestManager* download_request_manager() const { 272 DownloadRequestManager* download_request_manager() const {
255 return download_request_manager_.get(); 273 return download_request_manager_.get();
256 } 274 }
257 275
258 SaveFileManager* save_file_manager() const { 276 SaveFileManager* save_file_manager() const {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Resumes any blocked request for the specified RenderView. 352 // Resumes any blocked request for the specified RenderView.
335 void ResumeBlockedRequestsForRenderView(int render_process_host_id, 353 void ResumeBlockedRequestsForRenderView(int render_process_host_id,
336 int render_view_id); 354 int render_view_id);
337 355
338 // Cancels any blocked request for the specified RenderView. 356 // Cancels any blocked request for the specified RenderView.
339 void CancelBlockedRequestsForRenderView(int render_process_host_id, 357 void CancelBlockedRequestsForRenderView(int render_process_host_id,
340 int render_view_id); 358 int render_view_id);
341 359
342 private: 360 private:
343 FRIEND_TEST(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies); 361 FRIEND_TEST(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies);
362 FRIEND_TEST(ResourceDispatcherHostTest,
363 IncrementOutstandingRequestsMemoryCost);
364 FRIEND_TEST(ResourceDispatcherHostTest,
365 CalculateApproximateMemoryCost);
366
344 class ShutdownTask; 367 class ShutdownTask;
345 368
346 friend class ShutdownTask; 369 friend class ShutdownTask;
347 370
348 struct BlockedRequest { 371 struct BlockedRequest {
349 BlockedRequest(URLRequest* url_request, bool mixed_content) 372 BlockedRequest(URLRequest* url_request, bool mixed_content)
350 : url_request(url_request), 373 : url_request(url_request),
351 mixed_content(mixed_content) { 374 mixed_content(mixed_content) {
352 } 375 }
353 URLRequest* url_request; 376 URLRequest* url_request;
(...skipping 27 matching lines...) Expand all
381 // renderer in the event of a download. If |allow_delete| is true and no IO 404 // renderer in the event of a download. If |allow_delete| is true and no IO
382 // is pending, the request is removed and deleted. 405 // is pending, the request is removed and deleted.
383 void CancelRequest(int render_process_host_id, 406 void CancelRequest(int render_process_host_id,
384 int request_id, 407 int request_id,
385 bool from_renderer, 408 bool from_renderer,
386 bool allow_delete); 409 bool allow_delete);
387 410
388 // Helper function for regular and download requests. 411 // Helper function for regular and download requests.
389 void BeginRequestInternal(URLRequest* request, bool mixed_content); 412 void BeginRequestInternal(URLRequest* request, bool mixed_content);
390 413
414 // Updates the "cost" of outstanding requests for |render_process_host_id|.
415 // The "cost" approximates how many bytes are consumed by all the in-memory
416 // data structures supporting this request (URLRequest object,
417 // HttpNetworkTransaction, etc...).
418 // The value of |cost| is added to the running total, and the resulting
419 // sum is returned.
420 int IncrementOutstandingRequestsMemoryCost(int cost,
421 int render_process_host_id);
422
423 // Estimate how much heap space |request| will consume to run.
424 static int CalculateApproximateMemoryCost(URLRequest* request);
425
391 // The list of all requests that we have pending. This list is not really 426 // The list of all requests that we have pending. This list is not really
392 // optimized, and assumes that we have relatively few requests pending at once 427 // optimized, and assumes that we have relatively few requests pending at once
393 // since some operations require brute-force searching of the list. 428 // since some operations require brute-force searching of the list.
394 // 429 //
395 // It may be enhanced in the future to provide some kind of prioritization 430 // It may be enhanced in the future to provide some kind of prioritization
396 // mechanism. We should also consider a hashtable or binary tree if it turns 431 // mechanism. We should also consider a hashtable or binary tree if it turns
397 // out we have a lot of things here. 432 // out we have a lot of things here.
398 typedef std::map<GlobalRequestID,URLRequest*> PendingRequestList; 433 typedef std::map<GlobalRequestID,URLRequest*> PendingRequestList;
399 434
400 // Deletes the pending request identified by the iterator passed in. 435 // Deletes the pending request identified by the iterator passed in.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 ScopedRunnableMethodFactory<ResourceDispatcherHost> method_runner_; 505 ScopedRunnableMethodFactory<ResourceDispatcherHost> method_runner_;
471 506
472 // True if the resource dispatcher host has been shut down. 507 // True if the resource dispatcher host has been shut down.
473 bool is_shutdown_; 508 bool is_shutdown_;
474 509
475 typedef std::vector<BlockedRequest> BlockedRequestsList; 510 typedef std::vector<BlockedRequest> BlockedRequestsList;
476 typedef std::pair<int, int> ProcessRendererIDs; 511 typedef std::pair<int, int> ProcessRendererIDs;
477 typedef std::map<ProcessRendererIDs, BlockedRequestsList*> BlockedRequestMap; 512 typedef std::map<ProcessRendererIDs, BlockedRequestsList*> BlockedRequestMap;
478 BlockedRequestMap blocked_requests_map_; 513 BlockedRequestMap blocked_requests_map_;
479 514
515 // Maps the render_process_host_ids to the approximate number of bytes
516 // being used to service its resource requests. No entry implies 0 cost.
517 typedef std::map<int, int> OutstandingRequestsMemoryCostMap;
518 OutstandingRequestsMemoryCostMap outstanding_requests_memory_cost_map_;
519
520 // |max_outstanding_requests_cost_per_process_| is the upper bound on how
521 // many outstanding requests can be issued per render process host.
522 // The constraint is expressed in terms of bytes (where the cost of
523 // individual requests is given by CalculateApproximateMemoryCost).
524 // The total number of outstanding requests is roughly:
525 // (max_outstanding_requests_cost_per_process_ /
526 // kAvgBytesPerOutstandingRequest)
527 int max_outstanding_requests_cost_per_process_;
528
480 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost); 529 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost);
481 }; 530 };
482 531
483 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_ 532 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/resource_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698