一、压测准备:
1)压测前了解系统架构:
系统架构由SLB(负载均衡服务器)+ECS(webserver (nignx 1.6 +php5.4))+redis 2.8(缓存服务器,主要用于数据库数据和session,支持主从同步,以及集群) +数据库代理服务+RDS(数据库 使用一主五从)
+xunsearch 1.4.9 (搜索专用,将数据库中的数据通过索引关联起来,使得查询更快)
2)对服务器的硬件信息进行统计,记录压测的的代码时间,RDS数据量
3)
4)输出性能测试报告
下面我来介绍一个传参的时候遇到的一些问题:
1)传参的时候,参数是加密的,这个问题,我找开发,协助绕过传参加密的过程
2)传参的时候,数字签名,解决方法,需要找开发,编写数字签名算法,进行sign传参
分享一下sign编写的代码,签名先将传的json字符串按照abcd排序,然后在进行md5加密
package com.jybd.shop.comm.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SignUtils {
public static String sqrtMap(HashMap<String, String> map) {
List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(map.entrySet());
//排序
Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
//return (o2.getValue() - o1.getValue());
return (o1.getKey()).toString().compareTo(o2.getKey());
}
});
//排序后
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < infoIds.size(); i++) {
String content = infoIds.get(i).toString();
if (!infoIds.get(i).getKey().equals("sign")) {
buffer.append(content + "&");
}
// System.out.println(buffer);
}
buffer.append("key=liuyan");
String result = "";
if (buffer.length() > 0) {
result = buffer.substring(0, buffer.length());
}
return result;
}
public List asSortedList(HashMap map) {
//这里将map.entrySet()转换成list
List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(map.entrySet());
System.out.print(list);
//然后通过比较器来实现排序
return list;
}
public String getMD5(String val) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(val.getBytes());
byte[] m = md5.digest();//加密
StringBuffer sb = new StringBuffer();
for (int i = 0; i < m.length; i++) {
sb.append(m[i]);
}
return sb.toString();
}
/**
* 作用:得到一个sign的值
*/
public static String getSign(HashMap<String, String> paraMap) throws NoSuchAlgorithmException {
String params = sqrtMap(paraMap);
// LogUtil.e("params-->",params);
String md5 = getMd5Value(params);
// LogUtil.e("sign-->",md5);
return md5;
}
private static String getString(byte[] b) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < b.length; i++) {
int a = b[i];
if (a < 0)
a += 256;
if (a < 16)
buf.append("0");
buf.append(Integer.toHexString(a));
}
return buf.toString(); //32位
}
/***
* MD5加码 生成32位md5码
*/
public static String string2MD5(String inStr){
MessageDigest md5 = null;
try{
md5 = MessageDigest.getInstance("md5");
}catch (Exception e){
System.out.println(e.toString());
e.printStackTrace();
return "";
}
char[] charArray = inStr.toCharArray();
byte[] byteArray = new byte[charArray.length];
for (int i = 0; i < charArray.length; i++)
byteArray[i] = (byte) charArray[i];
byte[] md5Bytes = md5.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++){
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16)
hexValue.append("0");
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
}
public static String getMd5Value(String sSecret) {
try {
MessageDigest bmd5 = MessageDigest.getInstance("MD5");
bmd5.update(sSecret.getBytes());
int i;
StringBuffer buf = new StringBuffer();
byte[] b = bmd5.digest();
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
return buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}