Skip to content

Instantly share code, notes, and snippets.

Avatar

bohr bohrqiu

View GitHub Profile
@bohrqiu
bohrqiu / nginx-tuning.md
Created Dec 11, 2017 — forked from denji/nginx-tuning.md
NGINX tuning for best performance
View nginx-tuning.md

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@bohrqiu
bohrqiu / DataSourceHealthIndicator.java
Created Nov 5, 2015
DataSourceHealthIndicator with timeout
View DataSourceHealthIndicator.java
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@bohrqiu
bohrqiu / .xml
Created Aug 18, 2015
build source to binary jar
View .xml
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
View gist:c8d8d19b9ed179d46390
@RestController
public class AsyncController {
private static final Logger logger = LoggerFactory.getLogger(AsyncController.class);
private static AtomicInteger ai = new AtomicInteger();
@Autowired
private UserQueryService userQueryService;
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
@bohrqiu
bohrqiu / gist:40fdc0734f171eb5486e
Created Sep 23, 2014
查看java进程启动线程数
View gist:40fdc0734f171eb5486e
for pid in `ps -ef |grep java| grep -v 'grep'| awk '{print $2}'`
do
cat /proc/$pid/status |grep Threads | awk '{print $2}'
done
View gist:1f32d3575e89ec09e8d5
MAVEN_OPTS='-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8765'

transport

这里通常使用套接字传输。但是在 Windows 平台上也可以使用共享内存传输。

server

@bohrqiu
bohrqiu / monitor_create_thread
Last active Aug 29, 2015
btrace script monitor create new thread
View monitor_create_thread
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TracingScript {
public static int count = 0;
@OnMethod(clazz = "java.lang.Thread", method = "start")
public static void onNewThread() {
@bohrqiu
bohrqiu / gist:817669f38261104c31d8
Created Aug 21, 2014
tomcat-maven-plugin config ssl
View gist:817669f38261104c31d8
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
@bohrqiu
bohrqiu / Copier.java
Last active Apr 24, 2017
对象属性复制工具类,采用javassit生成源代码实现属性复制.并能实现包装类型和基础类型之间的转换
View Copier.java
package bohr.javassist;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.BeanInfo;
@bohrqiu
bohrqiu / RequestBindingTest.java
Last active Nov 22, 2016
http request 转换为对象
View RequestBindingTest.java
import com.google.common.collect.Maps;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.core.convert.converter.Converter;