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. 使用Dlib来运行基于CNN的人脸检测

    检测结果如下 这个示例程序需要使用较大的内存,请保证内存足够.本程序运行速度比较慢,远不及OpenCV中的人脸检测. 注释中提到的几个文件下载地址如下 http://dlib.net/face_det ...

  2. nginx AIO机制与sendfile机制

    nginx AIO机制与sendfile机制 从0.8.11版本开始, nginx 开始支持Linux native aio,如何在nginx里配置使用这套机制是本文介绍的重点.在下面的示例配置中,几 ...

  3. C# 图片识别(支持21种语言)

    图片识别的技术到几天已经很成熟了,只是相关的资料很少,为了方便在此汇总一下(C#实现),方便需要的朋友查阅,也给自己做个记号. 图片识别的用途:很多人用它去破解网站的验证码,用于达到自动刷票或者是批量 ...

  4. Linux安装ElasticSearch-2.2.0

    1.下载ElasticSearch-2.2.0安装包 https://www.elastic.co/downloads/elasticsearch 2.安装ElasticSearch-2.2.0 rp ...

  5. .Net jsc.exe 编译js 成exe

  6. Oracle 12C -- 网络性能调优

    1.传输数据压缩 网络性能主要受两方面影响:bandwidth和data volume. 在网络层对数据进行压缩,可以减少对网络带宽的需求.而且对应用是透明的. 如果是CPU是瓶颈时开启网络层数据压缩 ...

  7. MySQL经常使用技巧

    建表 每一个表都有一个id字段,最好为UNSIGNED.如 INT(9) UNSIGNED NOT NULL 在表使用一段时间后,使用PROCEDURE ANALYSE得到建议,如select * f ...

  8. Linux shell下30个有趣的命令

    Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...

  9. FreeSWITCH快速录音

    一.背景 测试人员反映FreeSWITCH录音不及时,需要大约5秒的时间才能捕获到RTP流. 二.原因及解决 查了下资料,FreeSWITCH默认的录音参数配置是开启缓冲的, 即RTP流大小到达655 ...

  10. java appium webview切换处理

    Set<String> contexts = driver.getContextHandles(); for(String item :contexts){ // NATIVE_APP / ...