Process-Display-Process (PDP) pattern

Solution :- Process-Display-Process Desgin.
In this we adopt a approach which will process a small set of data first and then display the results to the user. While the user is having a look at the given results we can process the remaining results in the background and store them for further use.

Suppose we have a requirement, where we need to query on a table having a million records and fetch ten thound of them to display it to the user. But we sure can not display ten thousand records at a time, so we devide the records into the batches of 100 records each and the user can then scrole through the batches.

The Normal design would implement a Servlet and stateless session bean. The Session Bean queries the database based on the query criteria and then passes on the result set bound in PBV (pass-by-value) objects to the servlet. The servlet then Displays first batch and subsequent batches to the user based on this query data.

In this design (PDP pattern) we will make use of Servlets and Stateful session beans. The stateful session bean will have two methods, one for selecting the first batch, and another for selecting the remaining of the records. When the client enters some query criteria, these are passed to the first method of the stateful session bean (typically getFirstBatchResults() ). This method will then process the first batch results and send them back to the Servlet. The servlet displays the results to user making use of ( Response.flushBuffer() ). The query to database for selecting first batch can be made faster by using database features which allow you to select the "top n" records from the results.

After this, the control is still in the servlet. So we can call the second method of the Statefull session bean. This method ( typically getAllResults() ) will fetch all the records from the database and store them in the stateful session bean's privatte variable (arraylist). When the user wants to scroll through the records, we simply try to get that perticular batch from the stateful session bean. The getAllrecords() method needs to ommit the first batch results from subsequently adding to the arraylist.

Advantages :-
1. This gives the user a feeling that the response is quite fast.
2. Since the most of the data is stored in the Stateful Session Bean, It reduces the size of HttpSession.

Disadvantages / limitations :-
1. It can not be used where in the user is required to show the summery of all the results. In that case we need to process all the records before we can show anything to the user.
2. It results into two network calls for the same query criteria.
3. Thread safe ness of the methods needs to be checked, as we are operating on a private variable of the Stateful Session Bean.
4. If the user needs to sort the records based on some perticular columns, then this can not be implemented.
1 replies in this thread Reply
Read more Process-Display-Process (PDP) pattern.
Posted By: Bob Lee on October 17, 2001 in response to this message.
First, for an argument as to why a stateful session bean should absolutely not be used in this situation, I'll point you here: http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html.

Second, this is just a page-by-page iterator, and you can find it in the Sun blueprints.

The way you should set this up is with a stateless session bean with a single method, getRows(int startIndex, int pageSize,...).

If you're lucky enough to have jdbc 2.0, you can query the entire set and return only the window of rows requested using ResultSet.setFetchSize(pageSize) and ResultSet.absolute(startIndex). You can also use prepared statements here to make things more efficient. If you want to sort by a particular column, just pass it as a parameter to your session bean and generate it on the fly.

If you’re stuck with older drivers, you can use database-specific parameters to retrieve the results a page at a time.
阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要在Windows上配置Prometheus的process-exporter,可以按照以下步骤进行操作: 1. 下载process-exporter的Windows版本,可以从process-exporter的官方GitHub页面上下载:https://github.com/ncabatoff/process-exporter/releases 2. 将下载的可执行文件解压缩到一个合适的目录中,例如C:\Program Files\process-exporter。 3. 编写一个process-exporter的配置文件,指定需要监控的进程以及相关参数,例如: ``` process_names: - firefox.exe - chrome.exe windows_exporter: log_queries: true ``` 将该配置文件保存为process-exporter.yml。 4. 在Prometheus的配置文件prometheus.yml中添加以下内容,以启用process-exporter: ``` scrape_configs: - job_name: 'process-exporter' static_configs: - targets: ['localhost:9256'] ``` 注意,process-exporter默认监听端口9256。 5. 保存并重新启动Prometheus和process-exporter。 现在,Prometheus就可以监控Windows上的进程了。可以通过Prometheus的web界面来查看相关的指标,并使用PromQL语言进行查询和分析。例如,可以使用以下查询来查看chrome.exe的CPU使用率: ``` 100 * (1 - avg by (instance)(rate(process_cpu_seconds_total{process_name="chrome.exe"}[5m]))) ``` ### 回答2: 配置Prometheus的process-exporter可以通过以下步骤完成: 1. 首先,从Process Exporter的GitHub页面(https://github.com/ncabatoff/process-exporter)下载最新版本的二进制文件。根据操作系统的类型,选择对应的二进制文件,例如Windows选择`.exe`文件。 2. 将下载的二进制文件解压缩到一个适当的位置,例如C:\process-exporter。 3. 在解压缩目录中创建一个名为`process-exporter.yml`的配置文件,该文件将定义要监控的进程列表和其他选项。 4. 在配置文件中指定要监控的进程。例如,可以在`process_names`部分添加以下行来监控一个名为`my_process`的进程: ```yaml process_names: - my_process ``` 你也可以添加多个进程名称,按需监控。 5. 配置Prometheus以收集process-exporter的指标。在Prometheus的配置文件(prometheus.yml)中添加以下具有适当地址和端口的`scrape_configs`部分: ```yaml scrape_configs: - job_name: 'process_exporter' static_configs: - targets: ['localhost:9256'] ``` 这将告诉Prometheus在本地主机上的9256端口上收集来自process-exporter的指标。 6. 保存并关闭Prometheus配置文件。 7. 打开一个命令提示符窗口,并导航到process-exporter的解压缩目录。 8. 在命令提示符中运行以下命令启动process-exporter: ```bash process-exporter.exe --config.path=process-exporter.yml ``` 9. 确保Prometheus服务器正在运行,然后重新加载配置文件。 10. 访问Prometheus的Web界面,并导航到“Targets”选项卡。您应该看到一个名为`process_exporter`的目标显示为"UP",表示process-exporter和Prometheus之间的连接正常。 11. 接下来,您可以在Prometheus中使用适当的查询来检索和可视化process-exporter提供的指标数据。 通过按照以上步骤配置和启动process-exporter,您将能够监控和收集有关指定进程的性能指标,并将其集成到Prometheus监控系统中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xxcc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值