throttle proc check (public)

 throttle[i] check

Defined in packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl

This method should be called once per request that is monitored. It should be called after authentication such we have already the userid if the user is authenticated.

Partial Call Graph (max 5 caller/called nodes):
%3 test_test_cr_items test_cr_items (test xotcl-core) throttle proc check throttle proc check test_test_cr_items->throttle proc check test_test_xo_db_object test_xo_db_object (test xotcl-core) test_test_xo_db_object->throttle proc check test_xotcl_core_tutorial_1 xotcl_core_tutorial_1 (test xotcl-core) test_xotcl_core_tutorial_1->throttle proc check test_xotcl_core_tutorial_2 xotcl_core_tutorial_2 (test xotcl-core) test_xotcl_core_tutorial_2->throttle proc check

Testcases:
xotcl_core_tutorial_1, xotcl_core_tutorial_2, test_xo_db_object, test_cr_items
Source code:
#set t0 [clock milliseconds]

:get_context
# :log "### check"

#
# We could as well pass the whole header set via
#
#  {*}[ns_set array [ns_conn headers]]
#
# but since this code is time critical, just pass the information
# actually needed.
#
set hdrs [ns_conn headers]
lassign [:throttle_check ${:requester} ${:pa} ${:url}  [ns_conn start] [ns_guesstype [ns_conn url]] ${:community_id}  [list  pool [ns_conn pool]  Sec-Fetch-Dest [ns_set iget $hdrs Sec-Fetch-Dest]  Range [ns_set iget $hdrs Range]  ]]  toMuch ms repeat
#set t1 [clock milliseconds]

#
# result == 0 OK
# result < 0 blocked
# result > 0 This web server is only open for interactive usage
#
if {$repeat > 0} {
  :add_statistics repeat ${:requester} ${:pa} ${:url} ${:query}
  if {$repeat > 1} {
    set result 1
  } else {
    set result -1
  }
} elseif {$toMuch} {
  :log "*** we have to refuse user ${:requester} with $toMuch requests"
  :add_statistics reject ${:requester} ${:pa} ${:url} ${:query}
  set result $toMuch
} elseif {$ms} {
  :log "*** we have to block user ${:requester} for $ms ms"
  :add_statistics throttle ${:requester} ${:pa} ${:url} ${:query}
  after $ms
  :log "*** continue for user ${:requester}"
  set result 0
} else {
  set result 0
}
#set tend [clock milliseconds]
#if {$tend - $t0 > 500} {
#  ns_log warning "throttle_filter slow, can lead to filter time >1sec: total time [expr {$tend - $t0}], t1 [expr {$t1 - $t0}]"
#}

return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: