public class BackPressureStatsTrackerImpl implements BackPressureStatsTracker {

   private static final Logger LOG = LoggerFactory.getLogger(BackPressureStatsTrackerImpl.class);

   /** Maximum stack trace depth for samples. */
static final int MAX_STACK_TRACE_DEPTH = 3; /** Expected class name for back pressure indicating stack trace element. */
static final String EXPECTED_CLASS_NAME = "org.apache.flink.runtime.io.network.buffer.LocalBufferPool"; /** Expected method name for back pressure indicating stack trace element. */
static final String EXPECTED_METHOD_NAME = "requestBufferBuilderBlocking"; /** Lock guarding trigger operations. */
private final Object lock = new Object(); /* Stack trace sample coordinator. */
private final StackTraceSampleCoordinator coordinator;
@Override
public BufferBuilder requestBufferBuilderBlocking() throws IOException, InterruptedException {
return toBufferBuilder(requestMemorySegment(true));
}

private MemorySegment requestMemorySegment(boolean isBlocking) throws InterruptedException, IOException {
   synchronized (availableMemorySegments) {
      returnExcessMemorySegments();
      boolean askToRecycle = owner
!= null;
      // fill
availableMemorySegments with at least one element, wait if required
      while (availableMemorySegments.isEmpty())
{
         if (isDestroyed) {
            throw new IllegalStateException("Buffer
pool is destroyed.");
         }
         if (numberOfRequestedMemorySegments
< currentPoolSize) {
            final MemorySegment segment = networkBufferPool.requestMemorySegment();
            if (segment != null) {
               numberOfRequestedMemorySegments++;
               return segment;
            }
         }
         if (askToRecycle)
{
            owner.releaseMemory(1);
         }
         if (isBlocking)
{
            availableMemorySegments.wait(2000);
         }
         else {
            return null;
         }
      }
      return availableMemorySegments.poll();
   }
/**
* Returns back pressure statistics for a operator. Automatically triggers stack trace sampling
* if statistics are not available or outdated.
*
* @param vertex Operator to get the stats for.
* @return Back pressure statistics for an operator
*/
public Optional<OperatorBackPressureStats> getOperatorBackPressureStats(ExecutionJobVertex vertex) {
synchronized (lock) {
final OperatorBackPressureStats stats = operatorStatsCache.getIfPresent(vertex);
if (stats == null || backPressureStatsRefreshInterval <= System.currentTimeMillis() - stats.getEndTimestamp()) {
triggerStackTraceSampleInternal(vertex);
}
return Optional.ofNullable(stats);
}
}
/**
* Triggers a stack trace sample for a operator to gather the back pressure
* statistics. If there is a sample in progress for the operator, the call
* is ignored.
*
* @param vertex Operator to get the stats for.
* @return Flag indicating whether a sample with triggered.
*/
private boolean triggerStackTraceSampleInternal(final ExecutionJobVertex vertex) {
assert(Thread.holdsLock(lock)); if (shutDown) {
return false;
} if (!pendingStats.contains(vertex) &&
!vertex.getGraph().getState().isGloballyTerminalState()) { Executor executor = vertex.getGraph().getFutureExecutor(); // Only trigger if still active job
if (executor != null) {
pendingStats.add(vertex); if (LOG.isDebugEnabled()) {
LOG.debug("Triggering stack trace sample for tasks: " + Arrays.toString(vertex.getTaskVertices()));
} CompletableFuture<StackTraceSample> sample = coordinator.triggerStackTraceSample(
vertex.getTaskVertices(),
numSamples,
delayBetweenSamples,
MAX_STACK_TRACE_DEPTH); sample.handleAsync(new StackTraceSampleCompletionCallback(vertex), executor); return true;
}
} return false;
}

生产BackPressure 的代码的更多相关文章

  1. WebSocket :Nginx+WebSocket内部路由策略推送服务器的实现(附可生产环境应用代码)

    1.项目背景 前几天写了一篇WebSocket推送的博客:WebSocket :用WebSocket实现推送你必须考虑的几个问题 支持的连接数大概几千个,具体数量依赖于tomcat能并发的线程数,但很 ...

  2. Java生产消费者模型——代码解析

    我们将生产者.消费者.库存.和调用线程的主函数分别写进四个类中,通过抢夺非线程安全的数据集合来直观的表达在进行生产消费者模型的过程中可能出现的问题与解决办法. 我们假设有一个生产者,两个消费者来共同抢 ...

  3. NGINX+UWSGI部署生产的DJANGO代码

    并且NGINX不用ROOT帐户哟. 1,编译安装NGINX及UWSGI及DJANGO,不表述 2,将NGINX文件夹更改为普通用户拥有.但执行文件NGINX仍为ROOT,运行如下命令加入特殊权限标志位 ...

  4. CSS 代码技巧与维护 ★ Mozilla Hacks – the Web developer blog

    原文链接:https://hacks.mozilla.org/2016/05/css-coding-techniques/ 译文链接 :http://www.zcfy.cc/article/css-c ...

  5. 使用神经网络来识别手写数字【译】(三)- 用Python代码实现

    实现我们分类数字的网络 好,让我们使用随机梯度下降和 MNIST训练数据来写一个程序来学习怎样识别手写数字. 我们用Python (2.7) 来实现.只有 74 行代码!我们需要的第一个东西是 MNI ...

  6. 使用delphi+intraweb进行微信开发1~4代码示例

    前几讲重点阐述的是使用iw进行微信开发的技术难点及解决方法,提供的都是代码片段(微信消息加解密是完整代码),实际上我始终感觉按照教程实作是掌握一门技术的最重要的方法!不过对于刚刚接触这类开发的朋友来说 ...

  7. JAVA版Kafka代码及配置解释

    伟大的程序员版权所有,转载请注明:http://www.lenggirl.com/bigdata/java-kafka.html.html 一.JAVA代码 kafka是吞吐量巨大的一个消息系统,它是 ...

  8. 本地修改js代码并时时生效的解决办法

    js作为客户端语言(当然它也可以作服务端语言),非常强悍,一般情况下,我们都是在开发阶段不停的改,然后上线之后就作为稳定运行的代码. 然而有时候可能因为js写得有问题,导致上线后,某些功能无法使用,这 ...

  9. 前端通信:SSE设计方案(二)--- 服务器推送技术的实践以及一些应用场景的demo(包括在线及时聊天系统以及线上缓存更新,代码热修复案例)

    距离上一篇博客,这篇文章的发布大概过了整整三个月.我也从饿了么度过了试用期,成为了正式员工.刚进来恰好遇到项目底层改造和迁移,将项目从angular全部迁移到vue上,所以适应这边的节奏和业务的开发任 ...

随机推荐

  1. Lambda表达式树

    1.常量表达式树 Func< + ); 使用表达式树的方式 ConstantExpression a = Expression.Constant(); ConstantExpression b ...

  2. 电信网关-天翼网关-GPON-HS8145C设置桥接路由拨号认证

    需求描述: 自从用了电信的200M光纤,解析卡成狗.打开域名3秒左右,不常见的域名8s左右.怀疑电信的网关有问题,故想让路由器拨号认证,进而设置dns解析域名 修改为路由器拨号认证,域名解析缓慢依然没 ...

  3. AWVS扫描工具使用教程

    上文AppScan扫描工具-工作原理&操作教程有写到Web安全漏洞扫描工具之一的APPScan,除此,还有另外一款国内使用比较主流的Web安全漏洞扫描工具——AWVS.相较于大容量的AppSc ...

  4. [POST] What Is the Linux fstab File, and How Does It Work?

    If you’re running Linux, then it’s likely that you’ve needed to change some options for your file sy ...

  5. ThinkPHP学习(二)

    书接前文. 我想前台填写内容,然后在后台保存一下,规划了一下前台要录入的内容,主要包括title.content两大内容.然后简单设计了一个前台页面(复杂的我得会啊),就在上篇文章的基础上直接加了: ...

  6. TensorFlow Google大会总结

    一.概述 介绍TPU,需要使用XLA编译,否则没有做内部优化,无法达到加速的效果: TPU相关的性能分析器: 二.新版本的输入库 之前TensorFlow的输入方式: feed_dict: 太过于低效 ...

  7. 【JQuery】jQuery(document).ready(function($) { });的几种表示方法及load和ready的区别

    jQuery中处理加载时机的几种方式 第一种: jQuery(document).ready(function() { alert("你好"); }); //或 $(documen ...

  8. android studio中使用git版本管理

    转载请标注来源:http://blog.csdn.net/lsyz0021/article/details/51842774 AndroidStudio中使用Git-初级篇(一)——从github上传 ...

  9. FCEUX金手指加强版 - 使用Lua脚本语言编写FC/NES金手指脚本

    一直觉得大部分的FC/NES模拟器的作弊码金手指不是那么方便使用, 比如魂斗罗1代, 玩家的武器可以通过修改0xAA的值来改变: 0x11为M弹(重机枪),0x12为F弹(圈圈),0x13为S弹(散弹 ...

  10. MySQL USING 和 HAVING 用法

    USING 用于表连接时给定连接条件(可以理解为简写形式),如 SELECT * FROM table1 JOIN table2 ON table1.id = table2.id   使用 USING ...