`
iwindyforest
  • 浏览: 230332 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
tomcat并发设置 tomcat
    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="1000" minSpareThreads="300"/>



    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         org.apache.coyote.http11.Http11Protocol - blocking Java connector
         org.apache.coyote.http11.Http11NioProtocol - non blocking Java connector
         org.apache.coyote.http11.Http11Nio2Protocol - non blocking Java connector
         org.apache.coyote.http11.Http11AprProtocol - the APR/native connector.
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" 
			   protocol="org.apache.coyote.http11.Http11NioProtocol" 
	           maxHttpHeaderSize="8192" 
			   useBodyEncodingForURI="true"
               maxThreads="1000" 
			   minSpareThreads="25" 			
               enableLookups="false" 
			   redirectPort="8443" 
			   acceptCount="100"
               compression="on" 
			   compressionMinSize="2048" 
			   compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="20000" 
			   disableUploadTimeout="true" 
			   URIEncoding="UTF-8"/>
	
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="5" SSLEnabled="true"
			clientAuth="false" keystoreFile="conf/keystore/.keystore" keystorePass="changeit" scheme="https" secure="true"
			sslProtocol="TLS" truststoreFile="conf/trusts/cacerts" />


set "JAVA_OPTS=-Xmx1536m -Xms1536m -Xmn200m -XX:PermSize=256m -XX:MaxPermSize=256m -Xverify:none -Xnoclassgc -XX:+DisableExplicitGC -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=85"

set "JAVA_OPTS=-Xmx3100m -Xms3100m -Xmn400m -XX:PermSize=256m -XX:MaxPermSize=256m -Xverify:none -Xnoclassgc -XX:+DisableExplicitGC -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=85"


C:\Java\Apache\bin>ab -n 1000 -c 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        11430 bytes

Concurrency Level:      1000
Time taken for tests:   3.310 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      11594000 bytes
HTML transferred:       11430000 bytes
Requests per second:    302.10 [#/sec] (mean)
Time per request:       3310.189 [ms] (mean)
Time per request:       3.310 [ms] (mean, across all concurrent requests)
Transfer rate:          3420.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  17.4      0     537
Processing:  1603 2222 303.8   2381    2629
Waiting:      181 1600 480.0   1424    2461
Total:       1603 2224 303.9   2382    2630

Percentage of the requests served within a certain time (ms)
  50%   2382
  66%   2450
  75%   2533
  80%   2552
  90%   2586
  95%   2604
  98%   2622
  99%   2626
 100%   2630 (longest request)


ehcache spring ehcache
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
        p:configLocation="classpath:resources/ehcache/ehcache.xml" />
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="cacheManagerFactory" />
    <cache:annotation-driven cache-manager="cacheManager" />


    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="druidDataSource" />
        <property name="typeAliasesPackage" value="com.java.mybatis.bean" />
        <property name="mapperLocations" value="classpath*:resources/mybatis/mapper/*.xml" />
    </bean>

    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.java.mybatis.mapper" />
    </bean>
</beans>
imprt csv file to a table in h2 database h2, h2 database, csvread, column not found
create table country 
as 
( select * from csvread('Z:/DOWNLOAD/csv/countries.csv', 'country_id;country_code;country_name', 'charset=UTF-8 fieldSeparator=; caseSensitiveColumnNames=false')) ;

--after import csv file to a table, if you got column not found while query
--becasue the table column generated is case sensitive, you need to add "" to columns like "contry_id" 
--the generated columns are all varchar type, you can only change it mannually.

alter table country alter column "country_id"  rename to country_id
alter table country alter column country_id bigint
Druid+Spring+MyBatis 配置 mybatis Spring+Mybatis 多数据源配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:init-config.properties</value>
		</property>
	</bean>
	
	<!-- enable component scanning (beware that this does not enable mapper scanning!) -->
	<context:component-scan base-package="org.zhuc.mybatis" />

	<!-- enable autowire -->
	<context:annotation-config />

	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		init-method="init" destroy-method="close">
		<!-- 基本属性 url、user、password -->
		<property name="url" value="${dataSource.url}" />
		<property name="username" value="${dataSource.username}" />
		<property name="password" value="${dataSource.password}" />
		<property name="connectionProperties" value="${dataSource.driver}"></property>

		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="1" />
		<property name="minIdle" value="1" />
		<property name="maxActive" value="20" />

		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="60000" />

		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />

		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />

		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />

		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize"
			value="20" />

		<!-- 配置监控统计拦截的filters -->
		<property name="filters" value="stat" />
	</bean>

	<!-- define the SqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="typeAliasesPackage" value="org.zhuc.mybatis.domain" />
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
		<property name="basePackage" value="org.zhuc.mybatis.mapper" />
	</bean>

	<!-- transaction manager, use JtaTransactionManager for global tx -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
		<qualifier value="isap" />
	</bean>

	<!-- 全注解方式   需加上@Transactional -->
	<tx:annotation-driven transaction-manager="transactionManager" />
	
	<!-- 事务控制的业务方法配 -->
	<!--  
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="page*" read-only="true" />
			<tx:method name="list*" read-only="true" />
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	-->
	<!-- 事务控制拦截 -->
	<!--  
	<aop:config proxy-target-class="true">
		<aop:advisor pointcut="execution(* org.zhuc..*.service..*Service.*(..))"
			advice-ref="txAdvice" />
	</aop:config>
	-->
	
	<!-- =================================================================== -->
	<!-- 数据源2 -->
	<bean id="dataSource2" class="com.alibaba.druid.pool.DruidDataSource"
		init-method="init" destroy-method="close">
		<!-- 基本属性 url、user、password -->
		<property name="url" value="${dataSource2.url}" />
		<property name="username" value="${dataSource2.username}" />
		<property name="password" value="${dataSource2.password}" />
		<property name="connectionProperties" value="${dataSource2.driver}"></property>

		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="1" />
		<property name="minIdle" value="1" />
		<property name="maxActive" value="20" />

		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="60000" />

		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />

		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="300000" />

		<property name="validationQuery" value="SELECT 'x'" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />

		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize"
			value="20" />

		<!-- 配置监控统计拦截的filters -->
		<property name="filters" value="stat" />
	</bean>
	
	<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource2" />
		<property name="typeAliasesPackage" value="org.zhuc.mybatis.domain2" />
	</bean>
	
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory2"/>
		<property name="basePackage" value="org.zhuc.mybatis.mapper2" />
	</bean>
	
	<bean id="transactionManager2"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource2" />
		<qualifier value="insurance" />
	</bean>

	<!-- 全注解方式 -->
	<tx:annotation-driven transaction-manager="transactionManager2" />
	
</beans>
InnoDB引擎的锁特性 mysql 骑虎的康盛,两难的站长,关于Discuz发展的讨论
说到底,这根就在这MySQL上了。大家都知道mysql傻快,但往往不知道为啥快。简而言之就是因为“简单”,程序代码简单,功能也简单——处理个简单SQL查询很快,一旦是多表连接多条件查询,立马现原形,要做结果差集操作?没门,这正是mysql不能被严格成为“关系型数据库”(RDBMS)的原因。
在discuz X系列以前,站长论坛累计的数据量不大,一般就百万条帖子吧。虽然dz代码有缺陷,mysql不给力但还是能跑跑的(忽然想起《活着》中那句‘急了也能跑’,哈哈)。到X推出后现今数据量超千万的站也不会少了,虽然康盛对新版程序构架优化、数据库优化分库上做了不少改进,但这些改进带来的一点提升却被暴增的新功能所吞噬尽,反而因为更加复杂的SQL或者因为服务器分表的多次查询延迟而更加恶化——代码级的优化已经无法环节系统的缓慢。mysql只能接受简单的查询,对于新增的关系复杂的功能多带来的复杂查询条件力不从心。

数据库此时就是整个系统的瓶颈。

即便采用了内存缓存技术(memcache),可总是有数据要写入数据库的,比如session,pv,在线时间等等。myisam一写表就锁表,遇上高流量即便没有发帖系统照样扛不住。你说换支持行锁的innodb引擎吧,可mysql不能再说自己飞快了,一个 SELECT count(*)就能让系统龟速。最坑爹的是才知道innodb的所谓行锁是锁索引,使用也是有条件的:

    InnoDB行锁是通过给索引上的索引项加锁来实现的,这一点MySQL与Oracle不同,后者是通过在数据块中对相应数据行加锁来实现的。InnoDB这种行锁实现特点意味着:只有通过索引条件检索数据,InnoDB才使用行级锁,否则,InnoDB将使用表锁!
    在实际应用中,要特别注意InnoDB行锁的这一特性,不然的话,可能导致大量的锁冲突,从而影响并发性能。下面通过一些实际例子来加以说明。
    (1)在不通过索引条件查询的时候,InnoDB确实使用的是表锁,而不是行锁。
    (2)由于MySQL的行锁是针对索引加的锁,不是针对记录加的锁,所以虽然是访问不同行的记录,但是如果是 使用相同的索引键,是会出现锁冲突的。应用设计的时候要注意这一点。
    (3)当表有多个索引的时候,不同的事务可以使用不同的索引锁定不同的行,另外,不论是使用主键索引、唯一索 引或普通索引,InnoDB都会使用行锁来对数据加锁。
    (4)即便在条件中使用了索引字段,但是否使用索引来检索数据是由MySQL通过判断不同执行计划的代价来决 定的,如果MySQL认为全表扫描效率更高,比如对一些很小的表,它就不会使用索引,这种情况下InnoDB将使用表锁,而不是行锁。因此,在分析锁冲突 时,别忘了检查SQL的执行计划,以确认是否真正使用了索引

    当我们用范围条件而不是相等条件检索数据,并请求共享或排他锁时,InnoDB会给符合条件的已有数据记录的 索引项加锁;对于键值在条件范围内但并不存在的记录,叫做“间隙(GAP)”,InnoDB也会对这个“间隙”加锁,这种锁机制就是所谓的间隙锁 (Next-Key锁)。






这真难办啊,myisam是快,可是大并发下锁表阻塞严重,还时不时抽风坏表;innodb支持事务(先不谈支持的程度)不坏表吧可速度就慢多了(尤其是对于论坛这种经常要做select count(*)操作的)。这mysql众多引擎,各有特色,可就没一顺手放心的,还是那句话,就一坑爹的要你命3000(不知道的去看周星星的《大内密探零零七》)。
可康盛已经被mysql所捆绑了,构架优化都是针对MySQL的,比如分表到服务器,查询SQL切分连表操作为多个单表查询。要换数据库?还不如重写DZ呢。
现有新增功能已经因为历史数据而产生多多的问题,也让数据库更加疲惫,所以对于站长对新功能的呼声,官方只能忽视了。
Global site tag (gtag.js) - Google Analytics