throttle在程序中的作用

throttle

http://www.iciba.com/throttle

N-COUNT (汽车、飞机的)节流阀,油门杆,油门踏板 The throttle of a motor vehicle or aircraft is the device, lever, or pedal that controls the quantity of fuel entering the engine and is used to control the vehicle‘s speed.

He gently opened the throttle, and the ship began to ease forward...

他轻轻松开油门杆,轮船开始缓缓前行。

You have to push the throttle forward for more power.

你得把油门杆往前推来加大马力。

https://en.wikipedia.org/wiki/Throttle

A throttle is the mechanism by which fluid flow is managed by constriction or obstruction.

An engine‘s power can be increased or decreased by the restriction of inlet gases (i.e., by the use of a throttle), but usually decreased. The term throttle has come to refer, informally and incorrectly, to any mechanism by which the power or speed of an engine is regulated.

中文为节流阀, 可以控制流速的 增加 和  减少, 主要目的是, 将流速控制在一个合理的区间, 既不高也不低。

web服务器应用

apache

https://www.owasp.org/images/0/04/Roberto_Suggi_Liverani_OWASPNZDAY2010-Defending_against_application_DoS.pdf

为了防护DOS攻击, APACHE web服务器, 以插件形式提供, 对一段窗口时间内 从单一客户端发起http请求频次的控制; 和 按照IP控制访问带宽的控制。

mod_throttle

-

limit the frequency of requests allowed from a

single client within a window of time

?

mod_bwshare

-

bandwidth throttling by HTTP client IP address

thttpd

http://www.acme.com/software/thttpd/

thttpd可做为嵌入式的服务器,消耗资源少, 但是也提供了throttle功能, 保证服务器的稳定性:

thttpd - tiny/turbo/throttling HTTP server

It also has one extremely useful feature (URL-traffic-based throttling) that no other server currently has.

http://www.acme.com/software/thttpd/thttpd_man.html#THROTTLING

The throttle file lets you set maximum byte rates on URLs or URL groups. You can optionally set a minimum rate too. The format of the throttle file is very simple. A # starts a comment, and the rest of the line is ignored. Blank lines are ignored. The rest of the lines should consist of a pattern, whitespace, and a number. The pattern is a simple shell-style filename pattern, using ?/**/*, or multiple such patterns separated by |.

Example:


# throttle file for www.acme.com

**              2000-100000  # limit total web usage to 2/3 of our T1,
                             # but never go below 2000 B/s
**.jpg|**.gif   50000        # limit images to 1/3 of our T1
**.mpg          20000        # and movies to even less
jef/**          20000        # jef‘s pages are too popular
    

thttpd实现

static void
read_throttlefile( char* tf )  // 读取配置

static int
check_throttles( connecttab* c ) // 检验是否超过控制的流量

static void
update_throttles( ClientData client_data, struct timeval* nowP ) // 定时器更新流量状态

前端应用

http://benalman.com/projects/jquery-throttle-debounce-plugin/

throttle

jQuery throttle / debounce allows you to rate-limit your functions in multiple useful ways. Passing a delay and callback to $.throttle returns a new function that will execute no more than once every delay milliseconds.

throttle 产生一个新的函数, 此函数当被重复调用的时候, 执行原始函数不超过一次, 在每个延迟周期中。

Using jQuery throttle / debounce, you can pass a delay and function to $.throttle to get a new function, that when called repetitively, executes the original function (in the same context and with all arguments passed through) no more than once every delay milliseconds.

Throttling can be especially useful for rate limiting execution of handlers on events like resize and scroll. Just take a look at the following usage example or the working throttling examples to see for yourself!

使用场景: 事件的处理函数中使用, 例如resize 和 scroll, 这些事件中的函数, 会被频繁调用。

解释, 在上面一行为 resize事件,对throttle产生的函数的调用, 下面一行为设定的delay事件到期后, 触发的原始函数的一次执行。

例如:

function log( event ) {
  console.log( $(window).scrollTop(), event.timeStamp );
};

// Console logging happens on window scroll, WAAAY more often
// than you want it to.
$(window).scroll( log );

// Console logging happens on window scroll, but no more than
// once every 250ms.
$(window).scroll( $.throttle( 250, log ) );

// Note that in jQuery 1.4+ you can unbind by reference using
// either the throttled function, or the original function.
$(window).unbind( ‘scroll‘, log );

debounce

Passing a delay and callback to $.debounce returns a new function that will execute only once, coalescing multiple sequential calls into a single execution at either the very beginning or end.

在一段连续触发的事件段中, 可以控制, 只在开始和结束后的指定事件后, 执行原始函数。

代码:

function ajax_lookup( event ) {
  // Perform an AJAX lookup on $(this).val();
};

// Console logging happens on keyup, for every single key
// pressed, which is WAAAY more often than you want it to.
$(‘input:text‘).keyup( ajax_lookup );

// Console logging happens on window keyup, but only after
// the user has stopped typing for 250ms.
$(‘input:text‘).keyup( $.debounce( 250, ajax_lookup ) );

// Note that in jQuery 1.4+ you can unbind by reference using
// either the throttled function, or the original function.
$(‘input:text‘).unbind( ‘keyup‘, ajax_lookup );
时间: 2024-08-18 21:34:37

throttle在程序中的作用的相关文章

Python之路52-html的本质及web程序中的作用

HTML 有一套规则,浏览器认识的规则 2.开发者: 学习html规则 开发后台程序 写html文件(充当模板的作用) 数据库获取数据,然后替换到html文件的指定位置(web框架) 3.本地测试 找到文件路径,直接打开浏览器 pycharm打开测试 4.编写html文件 doctype对应关系 html标签,标签内部可以写属性,html标签只能有一个 注释 <!-- 注释内容 --> 5.标签分类 自闭合标签,如 <meta charset="UTF-8">

c语言程序中static作用

这里是static是静态局部变量,不会随着函数的结束而撤销,放在main函数里是没有实际意义的,下面一个是static的例子:void f(){static int x=0;int y=0;x++;y++;printf("%d %d\n", x, y);}void main(){f();f();f();} 这里运行了3次f(),但是static只会被定义一次,并不会随着f()函数的结束而消亡,但是y是局部变量,运行了3次它就被创建了3次消亡了3次,所以它的输出为:1 12 13 1

浅谈多线程在java程序中的应用

在一个高并发的网站中,多线程是必不可少的.下面先说一下多线程在程序中的作用.1.提高前端请求的响应速度.当我们执行一个比较耗时的方法时,http请求得不到响应甚至会超时,这时如果业务上允许数据的延迟,我们可以使用多线程来进行处理比较耗时的方法.这样前端发送了请求,后端令开启了一个线程去处理任务,就不会阻塞主线程了.2.减清服务器的压力.包括我们的web容器,如tomcat.jetty等,还有数据库服务器等.因为我们使用了多线程,并且线程池大小有限制,如30,那么同时请求数据库的链接就限制为30了

NLOG在Console程序中运行时不起作用

把Web程序中的NLog.dll, NLog.config, NLog.xsd拷到Console程序中,发现运行不起作用,看了网上的示例教程,如http://www.cnblogs.com/sorex/archive/2013/01/31/2887174.html,试了下,多了个packages.config文件,里面内容如下: <?xml version="1.0" encoding="utf-8"?> <packages> <pac

python程序中if __name__ == &#39;__main__&#39;:的作用。

首先先用代码来看__name__的作用 1 ModuOne.py被调用程序 2 3 def MethodOne (varone): 4 print(__name__) 5 print(varone) 6 7 MethodOne("程序测试") 8 9 C:\python ModuOne.py #可以看到直接运行ModuOne.py时__name__被打印成"__main__" 10 __main__ 11 程序测试 #函数测试被执行 12 13 14 zuma.py

java程序中String args[]起什么作用?

在下面这个程序中String args[]起什么作用?我学过C++,String args[]与C++中的什么类似?如果是C++,想要输出字符串只要在下面写cout<<"...."<<endl;就可以了,void main()中的括号为空,而java中为什么要写String args[]呢? class Example{ public static void main(String args[]){ System.out.println("This i

Orchard 之:Widget,兼看 Layer 在权限控制中的作用

一:Widget 可以理解为控件,可以直接被页面所引用.行为类似与分部页面,比如,我们可以创建一个 商品列表 Widget,然后这个 Widget 就可以被很多页面所引用. 理解 Widget 这个概念,我们不得不理解另外两个概念: 1:Layer Orchard 默认有这么几个层,Default.Authenticated.Anonymous.Disabled.TheHomepage.Layer 用于承载什么时候 Widget 将会被展现,这么讲大家一定觉得很抽象,其实 Layer 存在的意义

java中static作用详解

static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何对象.也就是说,它不依赖类特定的实例,被类的所有实例共享. 只要这个类被加载,Java虚拟机就能根据类名在运行时数据区的方法区内定找到他们.因此,static对象可以在它的任何对象创建之前访问,无需引用任何对象. 用public修饰的static成员变量和成员方法本质是全局变量和全局方法,当声明它类

[转]MSI安装程序中的文件替换

原文链接:http://teach.hanzify.org/article/652-1233562028.html 前言 最近有汉化朋友问起如何不重新制作MSI文件,而直接用汉化好的文件替换MSI安装程序中的文件.为此,将本人的实践经验作个总结,供各位汉化人参考.有错误的地方烦请指正.※说明:目前可以用于MSI编辑的软件很多,但是有些软件在保存时会在MSI文件中写入一些自己的表或内容,有些会另外嵌入一个CAB文件,使得MSI文件增大.而这里提供的方法保证不会写入任何不必要的内容和文件.※关键点: