FLUSHALL FLUSHDB 命令会清空数据,而且从不失败,对于线上集群非常危险。 KEYS * 命令,当数据规模较大时使用,会严重影响Redis性能,也非常危险。 如果从根本上规避这些风险呢? Redis提供了非常简单且有效的方法,直接在配置文件中设置禁用这些命令。设置非常简单,如下
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command KEYS ""
zz from newsmth e进制是信息表示的最优解 | |
先考虑最优的定义 | |
假定总共有n位,每位m个状态,m*n=v | |
在v一定时,使得m^n最大 | |
也就是k(n)=(v/n)^n最大 |
public void testGrizzly(String ip, int port) throws IOException, InterruptedException, ExecutionException, TimeoutException, TException { | |
// init client | |
final FilterChainBuilder clientFilterChainBuilder = FilterChainBuilder.stateless(); | |
clientFilterChainBuilder.add(new TransportFilter()); | |
// clientFilterChainBuilder.add(new ThriftFrameFilter()); | |
clientFilterChainBuilder.add(new ThriftClientFilter()); | |
final TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); | |
final ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); |
FLUSHALL FLUSHDB 命令会清空数据,而且从不失败,对于线上集群非常危险。 KEYS * 命令,当数据规模较大时使用,会严重影响Redis性能,也非常危险。 如果从根本上规避这些风险呢? Redis提供了非常简单且有效的方法,直接在配置文件中设置禁用这些命令。设置非常简单,如下
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command KEYS ""
Protobuf 动态反射填充机制(JAVA) 十月 23rd, 2014 79 views 利用此方案可进行自动化Protobuf的功能拓展,核心代码如下
com.google.protobuf.GeneratedMessage.Builder builder;
Object object;
/* 遍历protobuf builder体 取出字段 */
for (int i = 0; i < builder.getDescriptorForType().getFields().size(); i++) {
Android/Java/Python平台的 Timsort 排序算法有 Bug[讨论] 2 月前• aoi 分享 •排序算法 , 算法
Timsort 是一个混合排序算法,综合了合并排序(Merge Sort)和插入排序(Insertion Sort)。 Tim Peters 于 2002 年为 Python 语言开发实现。Joshua Bloch 后来把这个混合排序算法移植到了 Java 语言(在 java.util.Collections.sort 和 java.util.Arrays.sort 中)。Joshua 设计了 Java 集合,他也曾经指出大多数二分查找算法有问题。目前,Android SDK、Sun JDK 和 OpenJDK 的默认排序算法均为 Timsort。鉴于这些平台都大受欢迎,大量计算机、云服务和手机都在使用 Timsort 算法。
Envisage 团队之前开发了一个名为 KeY 验证工具,成功验证了 Java 实现的计数和基数排序。在此之后,他们又在寻找新挑战。这次他们瞄上了 Timsort。不幸的是,他们这次没能证明 Timsort 的正确性。在更进一步分析之后,他们找到了该算法的 Bug。(有趣的是,Python实现中这个早已出现过了。)Envisage 在这篇文章展示了他们是如何发现这个Bug,最后也给出了修复方案。
› RSS订阅算法话题,关注算法相关的优秀工具资源和文章!
Intro | |
----- | |
This describes an adaptive, stable, natural mergesort, modestly called | |
timsort (hey, I earned it <wink>). It has supernatural performance on many | |
kinds of partially ordered arrays (less than lg(N!) comparisons needed, and | |
as few as N-1), yet as fast as Python's previous highly tuned samplesort | |
hybrid on random arrays. | |
In a nutshell, the main routine marches over the array once, left to right, | |
alternately identifying the next run, then merging it into the previous |
The following Nginx configuration enables CORS, with support for preflight requests, using a regular expression to define a whitelist of allowed origins, and various default values that may be needed to workaround incorrect browser implementations.
map $http_origin $cors_header {
default "";
"~^https?://[^/]+\.example\.com(:[0-9]+)?$" "$http_origin";
}
server {
...
location / {
要在终端输出带颜色的内容时,可以使用ANSI颜色设定。 \033[#m 为样式, \033[3#m 为前景色, \033[4#m 为背景色, \033[1;3#m 为粗体前景色。 | |
详细配色如下: | |
``` | |
\033[0m关 | |
\033[1m粗体\033[0m | |
\033[2m无\033[0m | |
\033[3m无\033[0m | |
\033[4m下划线\033[0m | |
\033[5m闪烁\033[0m |
今天在知乎看到这样一条bash命令(在类UNIX系统的shell环境下运行): 1:(){ :|:& };: 在终端执行完之后,我的Linux果然在一瞬间死掉了,风扇狂转… 查资料得: 这东西叫”Fork bomb”,2002年由Jaromil设计,通过不断fork出新的进程,一生二,二生四,四生八…然后指数爆炸,迅速耗光电脑资源。 我们来分析一下,把这条命令分解:
1. :() # 定义函数,函数名为":",即每当输入":"时就会自动调用{}内代码
2. { # ":"函數起始字元
3. : # 用递归方式调用":"函数本身
Nginx带宽控制
有个老项目,通过 Squid 提供文件下载功能,利用 delay_parameters 实现带宽控制,问题是我玩不转 Squid,于是盘算着是不是能在 Nginx 里找到类似的功能。
好消息是 Nginx 提供了 limit_rate 和 limit_rate_after,举个例子来说明一下:
location /download/ {
limit_rate_after 500k;
limit_rate 50k;
}