探查 JDBC Multipool 问题
| 负载平衡算法 采用负载平衡算法的 MultiPool 以 Round Robin 方式提供其连接,各连接在为其定义的所有 JDBC 连接池之间均匀分布。如果对某个连接的连接测试失败,MultiPool 会尝试从列表中的下一个池中提供连接。以下位置提供了更多详细信息:http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1023962 (English)。 因此,负载平衡既具有在若干个池间分配负载的长处,又能够在其中一个池不可用时提供一定程度的 Failover 能力。不过,如果采用负载平衡算法,将无法控制 MultiPool 响应来自其列表中不同池的连接请求的顺序及其 Failover 的目标池。 MultiPool 的限制 若要为 MultiPool 启用高可用性算法,需要考虑一些限制和前提条件。http://e-docs.bea.com/wls/docs81/jdbc/programming.html#1068130 (English) 中提供了详细信息。下面是对上述要点的总结:
|
| java.sql.SQLException: Pool connect failed : weblogic.common.ResourceException: testMultiPool(myMultiPool): weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool myMultiPool to allocate to applications, please increase the size of the pool and retry.. at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(JDBCUtil.java:160) |
Using Multi Data Sources with Oracle RAC - 11g Release 1 (10.3.6)
Attributes of a Multi Data Source
The multi data source may have the following attributes, depending on the role of Oracle RAC in your system—load balancing or failover:
-
AlgorithmType="Load-Balancing"orAlgorithmType="Failover"With the Load-Balancing option, connection requests are distributed among available data sources; with the High-Availability option, connection requests are served by the first available pool in the list. When a data source becomes defunct, connection requests are served by the next data source in the list.
-
FailoverRequestIfBusy="true"With the Failover algorithm, this attribute enables failover when all connections in a data source are in use.
-
TestFrequencySeconds="120"This attribute controls the frequency at which WebLogic Server checks the health of data sources previously marked as unhealthy to see if connections can be recreated and if the data source can be re-enabled. For more details see Chapter 5, "Configuring JDBC Multi Data Sources."
For fast failover of Oracle RAC nodes, set this value to a smaller interval, for example,
10(seconds).
Configuring JDBC Multi Data Sources - 11g Release 1 (10.3.6)
Choosing the Multi Data Source Algorithm
Before you set up a multi data source, you need to determine the primary purpose of the multi data source—failover or load balancing. You can choose the algorithm that corresponds with your requirements.
Failover
The Failover algorithm provides an ordered list of data sources to use to satisfy connection requests. Normally, every connection request to this kind of multi data source is served by the first data source in the list. If a database connection test fails and the connection cannot be replaced, or if the data source is suspended, a connection is sought sequentially from the next data source on the list.
Note:
This algorithm requires that Test Reserved Connections (TestConnectionsOnReserve) on the data source is enabled. If enabled, a connection in the first data source is tested to verify if the data source is healthy. If the connection fails the test, the multi data source uses a connection from the next data source listed in the multi data source. See Connection Testing Options for a Data Source for information about configuring TestConnectionsOnReserve.
JDBC is a highly stateful client-DBMS protocol, in which the DBMS connection and transactional state are tied directly to the socket between the DBMS process and the client (driver). For this reason, failover of a connection while it is in use is not supported.
Load Balancing
Connection requests to a load-balancing multi data source are served from any data source in the list. The multi data source selects data sources to use to satisfy connection requests using a round-robin scheme. When the multi data source provides a connection, it selects a connection from the data source listed just after the last data source that was used to provide a connection. Multi data sources that use the Load Balancing algorithm also fail over to the next data source in the list if a database connection test fails and the connection cannot be replaced, or if the data source is suspended.
Multi Data Source Fail-Over Limitations and Requirements
WebLogic Server provides the Failover algorithm for multi data sources so that if a data source fails (for example, if the database management system crashes), your system can continue to operate. However, you must consider the following limitations and requirements when configuring your system.
Test Connections on Reserve to Enable Fail-Over
Data sources rely on the Test Reserved Connections (TestConnectionsOnReserve) feature on the data source to know when database connectivity is lost. Testing reserved connections must be enabled for the data sources within the multi data source. WebLogic Server will test each connection before giving it to an application. With the Failover algorithm, the multi data source uses the results from connection test to determine when to fail over to the next data source in the multi data source. After a test failure, the data source attempts to recreate the connection. If that attempt fails, the multi data source fails over to the next data source.
No Fail-Over for In-Use Connections
It is possible for a connection to fail after being reserved, in which case your application must handle the failure. WebLogic Server cannot provide fail-over for connections that fail while being used by an application. Any failure while using a connection requires that the application code close the failed connection, and the transaction must be restarted from the beginning with a new connection.
Multi Data Source Failover Enhancements
The following enhancements improve failover processing for multi data sources:
-
Connection request routing enhancements to avoid requesting a connection from an automatically disabled (dead) data source within a multi data source. SeeConnection Request Routing Enhancements When a Data Source Fails.
-
Automatic failback on recovery of a failed data source within a multi data source. See Automatic Re-enablement on Recovery of a Failed Data Source within a Multi Data Source.
-
Failover for busy data sources within a multi data sources. See Enabling Failover for Busy Data Sources in a Multi Data Source.
-
Failover callbacks for multi data sources with the Failover algorithm. See Controlling Multi Data Source Failover with a Callback.
-
Failback callbacks for multi data sources with either algorithm. See Controlling Multi Data Source Failback with a Callback.
Linode VPS服务器介绍及购买指引
Linode优化建议
- 充分利用Linode服务器四核运算能力:榨干服务器,让进程运行在指定的CPU
- 简单快捷地备份Linode数据:备份数据库到S3
- 系统初装之后,建议进行一次LAMP最小优化
- 其他有关Linode的文章
Linode技术支持
Linode很适合作为Linux入门的材料。但对不熟悉shell的朋友,可能一开始安装软件、配置服务器都比较困难。
我提供有偿的技术支持,能解决大部分Linode上的配置问题,以及迁移网站的问题。详细请看:提供Linode技术支持。
FAQ
Q:什么样的人适合用linode?
A:由于Linode是Linux的VPS,所以需要有一定的Linux操作功底。当然,对不熟悉Linux服务器的人,也无疑是一次锻炼的机会。我就是在不熟悉Linux的情况下开始用Linode的。
Q:Linode主机价格如何?
A:Linode的VPS是相当价廉的VPS,价格要比Slicehost便宜约30%,比起MediaTemple就更加有优势。Linode的VPS有多种配置,最便宜一款$19.95。年付打9折。所有VPS配置列表可以在Linode首页找到。
Q:使用Linode会不会被墙?
A:每个Linode都有独立IP,这至少可保障你的网站不会被别人牵连。如果自己的IP被墙了,购买一个extra IP需要每个月1美金。BTW,可以在Linode上搭建VPN,极大方便平日流连Youtube、Facebook等资本主义国家的网站。
Q:Linode如何备份?
A:Linode提供了备份服务,但我更建议备份到Amazon S3。我编写了一个备份脚本,可以在Linode上用于备份数据。推荐使用。
Q:购买Linode应如何付款?
A:需要一张支持美金支付的信用卡,Linode不支持Paypal。经过测试,招行信用卡可以成功支付。
Q:Linode服务器速度如何?
A:请看 Linode4个机房的速度比较(杭州电信)。测试方法为单线程在4个机房的服务器上分别下载91M的文件。
| 机房 | 速度 |
| Fremont, CA | 140.90 KB/s |
| Dallas, TX | 8.33 KB/s |
| Atlanta, GA | 55.65 KB/s |
| Newark, NJ | 141.09 KB/s |
测试下载的文件和简要说明在此。
可以看到,Fremont机房和Newark机房都是很好的选择。我的Linode选择了Fremont机房,可以在此处实际测试一下服务器的速度(测出的数值除以8就是相应的KB/sec)。
注:最近也有朋友发现达拉斯机房的速度很不错,相比Fremont/Newark要好。所以建议大家购买时,自己实际测试下,选一个表现最好的。
Q:使用Linode如何进行备份?
A:Linode自己提供了backup的服务,按照不同等级的Plan进行收费。如果数据确实很重要,备份到Amazon S3也是个很好的选择。当然,我是把一些重要数据备份到Dreamhost服务器的。一个关键的优势在于:服务器放在国外,不管是连接S3还是连Dreamhost都是飞快,而且没有GFW。
Linode VPS 简介和使用指南
Linode VPS 购买教程
1、登录 Linode 官网 ,http://www.linode.com/
2、选择适合你自己的套餐,点击购买。
我选择linode 1024这个套餐,进行下面的购买及支付需要一张支持美元的信用卡,VISA、MASTER Card都可以。国内大部分银行的都可以,我这里使用的招商银行的信用卡。
Linode 服务器介绍及购买指引
如果您觉得本文对您有用处,你可以在购买的时候在Referral Code栏填写: "a396a5bacb1e332ff04e632704ea309036cf4c88"
如果有朋友看了我的文章觉得有用的话,恰好你又要购买 Linode 的 VPS,不妨使用我的 Refer 代码,于己无损,于人受益。
点击“continue”之后,回来到一个信息确认页面,有个协议需要确认,单击小方框,出现小勾就行了。
还有一个需要注意的是,好像不容易买到刚好一个月,比如我26号买的,这个月剩余的5天,我同样需要购买,实际上我支付了1个月15天,共计:23.82美元。事后,后台截图:
5、上步确认之后,你的Linode vps就购买完成了,手机上也收到了银行发来的信用卡支付信息,同时邮箱也受到订单的信息和帐号激活信息。
[转]java中判断字符串是否为数字的三种方法 - Javaphua Blog - BlogJava
1用JAVA自带的函数
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
2用正则表达式
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3用ascii码
public static boolean isNumeric(String str){
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
AwesomeChartJS
AwesomeChartJS is a simple Javascript library that can be used to create charts based on the HTML 5 canvas element.
The main goal during development was to pick sane defaults in order to let the user create simple charts quickly with just a couple of lines of code.
One can create at almost no time bar, pie, doughnut and Pareto charts.
Add an Expires or a Cache-Control Header in JSP - Stack Overflow
To disable browser cache JSP pages, create a Filter which is mapped on an url-pattern of*.jsp and does basically the following in the doFilter() method:
HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1 httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0 httpResponse.setDateHeader("Expires", 0); // Proxies.
This way you don't need to copypaste this over all JSP pages and clutter them with scriptlets.
To enable browser cache for static components like CSS and JS, put them all in a common folder like/static and create a Filter which is mapped on an url-pattern of /static/* and does basically the following in the doFilter() method:
httpResponse.setDateHeader("Expires", System.currentTimeMillis() + 604800000L); // 1 week in future.
WebLogic的多池Multi-Pool - 无法无天耗的日志 - 网易博客
客户的做法是这样的:
后台是Oracle的RAC数据库,他配置了一个多池,有2个Pool,PoolA主要连RAC的A实例,PoolB主要连RAC的B实例.其实他的PoolA和PoolB都是用了RAC格式的JDBC的写法,后面是一个主机列表,PoolA将A实例的IP写在了前面,PoolB将B实例的IP写在了前面,JDBC的算法是failover=yes load_banlance=no,这样每一个Pool将请求都发送到自己的第一个host的Oracle的实例上,在第一个host的Oracle实例出现故障时候切换到另外一个host的Oracle实例上.
PoolA和PoolB的JDBC的写法如下,注意failover=yes和load_banlance=yes,这样写的作用是当请求来的时候都转发给第一个host,只有出现第一个host有问题,才会将请求发送到第二个host:
WLS JDBC URL 的配置如下:
配置的多池的算法如果是High Availability的话,那么压力将始终压到一个Pool上面,另外一个Pool处于stand-by的状态,除非处理请求的Pool出现故障.客户的监控情况也是如此,发现压力都压在了一个Oracle的实例上.
如果多池的算法是Load Banlance的话,那么压力将平均分配到2个Pool上面.如果想使用多池的high availability的算法,则不要设置test的重试次数,如果设置了,则会出错抛出异常.
为了能使被标记为disable的PoolA能够恢复正常的连接,则需要设置HealthCheckFrequencySeconds的值在config.xml里面,该值在console上面没有.
另外还要能够使用TestConnectionsOnReserve.
