Authored by 陈峰

ssr 压测

... ... @@ -83,8 +83,10 @@ const component = {
product_id: _.toString(pid),
uid: req.user.uid || 0
};
const productPromise = model.product(params);
const vipPromise = req.user.uid ? model.getVipData(params) : Promise.resolve();
Promise.all([model.product(params), model.getVipData(params)]).then((result) => {
Promise.all([productPromise, vipPromise]).then((result) => {
let vipPrice = [];
// 最近浏览存储cookies
... ... @@ -97,7 +99,7 @@ const component = {
vipPrice.push({
level: vipLe(val.caption),
price: val.price,
currentVip: req.user.uid && parseInt(result[1].data.current_vip_level, 10) === vipLe(val.caption) ? 'active' : ''//eslint-disable-line
currentVip: result[1] && parseInt(result[1].data.current_vip_level, 10) === vipLe(val.caption) ? 'active' : ''//eslint-disable-line
});
}
... ... @@ -281,13 +283,19 @@ const component = {
yh_channel: CHANNEL_MAP[channel] || 1
};
model.mightLike(params).then(result => {
return model.mightLike(params).then(result => {
if (result && result.code === 200) {
res.json({
code: 200,
data: result.data.product_list || [],
message: result.message
});
} else {
res.json({
code: 400,
data: [],
message: ''
});
}
}).catch(next);
}
... ...
... ... @@ -16,7 +16,8 @@ const model = {
return api.get('', Object.assign({
method: 'app.product.data'
}, params), {
code: 200
code: 200,
cache: true
}).then(result => {
if (result.data) {
... ... @@ -108,7 +109,9 @@ const model = {
refundExchange(params) {
return api.get('', Object.assign({
method: 'app.product.refundExchange'
}, params));
}, params), {
cache: true
});
},
/**
... ...
... ... @@ -95,14 +95,14 @@ if (isProduction) {
Object.assign(module.exports, {
appName: 'm.yohoblk.com',
domains: {
api: 'http://api.yoho.yohoops.org/',
service: 'http://service.yoho.yohoops.org/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
},
memcache: {
master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],
slave: ['memcache1.yohoops.org:12112', 'memcache2.yohoops.org:12112', 'memcache3.yohoops.org:12112'],
session: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],
master: ['127.0.0.1:11211'],
slave: ['127.0.0.1:11211'],
session: ['127.0.0.1:11211'],
timeout: 100,
retries: 0
},
... ...
... ... @@ -12,7 +12,9 @@ if (config.useOneapm) {
require('oneapm');
}
var http = require('http');
const express = require('express');
const {Router} = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
... ... @@ -46,6 +48,12 @@ exports.createApp = (app) => {
if (app.locals.devEnv) {
app.use(devtools());
}
setTimeout(() => {
var {request, response} = require('express');
request.method = 'get';
request.url = 'http://m.yohoblk.com/product/pro_705324_863162/VANS%20Eraxie%20VN000EWZBLK1.html'
app.handle(request, response, ()=>{})
}, 1000)
app.use(global.yoho.hbs({
... ... @@ -123,4 +131,4 @@ exports.createApp = (app) => {
app.listen(config.port, function() {
logger.info(`worker is started at ${config.port}`);
});
}
};
... ...
... ... @@ -34,19 +34,27 @@ const render = (req, res, next) => {
};
if (!isDev) {
Promise.all([
rp(`https://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),
rp(`https://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),
]).then(results => {
renderer = createBundleRenderer(results[0], {
runInNewContext: false,
template,
clientManifest: results[1]
});
// Promise.all([
// rp(`https://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),
// rp(`https://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),
// ]).then(results => {
// renderer = createBundleRenderer(results[0], {
// runInNewContext: false,
// template,
// clientManifest: results[1]
// });
// });
const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`);
const clientManifest = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`);
renderer = createBundleRenderer(serverBundle, {
runInNewContext: false,
template,
clientManifest
});
}
const ssrRender = isDev ? (req, res, next) => {
let context = getContext(req);
... ...
... ... @@ -6,6 +6,7 @@ const commonConfig = require('./config/common');
exports.config = {
app_name: [commonConfig.appName],
tier_name: ['nodejs'],
license_key: 'UwAEUQcGVgBb27eSSlsXDlgaWx24a2deW0kABFAFTaf5bFYMT1MFGgdTb465AwBIAgxMA1k=',
logging: {
level: 'info'
... ...
... ... @@ -110,18 +110,18 @@
"stylelint-processor-html": "^1.0.0",
"uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9",
"vue": "^2.4.2",
"vue": "^2.4.4",
"vue-awesome-swiper": "^2.6.2",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.2.4",
"vue-infinite-scroll": "^2.0.1",
"vue-lazyload": "^1.0.6",
"vue-loader": "^13.0.2",
"vue-loader": "^13.0.5",
"vue-router": "^2.7.0",
"vue-server-renderer": "^2.4.2",
"vue-style-loader": "^3.0.1",
"vue-server-renderer": "^2.4.4",
"vue-style-loader": "^3.0.3",
"vue-swipe": "^2.0.3",
"vue-template-compiler": "^2.4.2",
"vue-template-compiler": "^2.4.4",
"vue-touch": "2.0.0-beta.3",
"vuex": "^2.4.0",
"webpack": "3.3",
... ...
process.env.NODE_ENV = 'production';
require('./app.js');
... ...
import axios from 'axios';
import config from 'config';
let axiosOptions = {
baseURL: config.axiosBaseUrl,
responseType: config.axiosResponseType,
headers: {}
axios.defaults.baseURL = config.axiosBaseUrl;
axios.defaults.responseType = config.axiosResponseType;
axios.defaults.headers = {
'X-Requested-With': 'XMLHttpRequest'
};
if (process.env.VUE_ENV !== 'server') {
axiosOptions.headers['X-Requested-With'] = 'XMLHttpRequest';
const isServer = process.env.VUE_ENV === 'server';
if (isServer) {
console.log(global.test)
}
const instanceAxios = axios.create(axiosOptions); // ssr不能使用全局的axios否则热更新会有问题
instanceAxios.interceptors.response.use(response => {
return response;
}, error => {
const errHandle = error => {
let msg = error && error.config ? `ssr api:[${error.config.method}] ${error.config.url} ${error.config.params || ''} ${error.response && error.response.data}` : 'axios error';
return Promise.reject(msg);
});
};
const request = (options) => {
options.headers = {
'is-server': isServer
};
return axios(options).then(res => res.data, errHandle);
};
export default {
post(url, data, options) {
return instanceAxios.post(url, data, options).then(res => res.data);
return request(Object.assign({
url,
data,
method: 'post',
}, options));
},
get(url, params) {
return instanceAxios.get(url, {params}).then(res => res.data);
get(url, params, options) {
return request(Object.assign({
url,
params,
method: 'get',
}, options));
},
put(url, data, options) {
return instanceAxios.put(url, data, options).then(res => res.data);
return request(Object.assign({
url,
data,
method: 'put',
}, options));
},
delete(url, params) {
return instanceAxios.delete(url, {params}).then(res => res.data);
delete(url, params, options) {
return request(Object.assign({
url,
params,
method: 'delete',
}, options));
}
};
... ...
... ... @@ -3,10 +3,9 @@ import {
SET_ENV
} from 'store/yoho/types';
const {app, router, store} = createApp();
export default context => {
return new Promise((resolve, reject) => {
const {app, router, store} = createApp();
const {url} = context;
const route = router.resolve(url).route;
... ...
... ... @@ -45,13 +45,8 @@ export default {
}
}
},
created() {
mounted() {
this.loadlList();
},
watch: {
skn() {
this.loadlList();
}
}
};
</script>
... ...
... ... @@ -38,9 +38,9 @@ const loadRoutes = (rous, paths, children) => {
}
};
export function createRouter() {
let routes = _.flattenDeep(loadRoutes(pages));
const routes = _.flattenDeep(loadRoutes(pages));
export function createRouter() {
return new Router({
mode: 'history',
routes,
... ...
... ... @@ -31,13 +31,14 @@ export default {
},
actions: {
[FETCH_PRODUCT_DETAIL]({commit, state}, {product_id}) {
let cacheItem = state.items[product_id];
// let cacheItem = state.items[product_id];
if (cacheItem && Date.now() - cacheItem.__lasttime < 1000 * 60 * 3) {
return Promise.resolve();
}
// if (cacheItem && Date.now() - cacheItem.__lasttime < 1000 * 60 * 3) {
// return Promise.resolve();
// }
return api.get(`/product/product_${product_id}.json`).then(res => {
if (res.code === 200) {
return commit(FETCH_PRODUCT_DETAIL, {product: res.data});
return Promise.all([
api.get(`/product/refundExchange/${res.data.product_skn}`),
api.get(`/product/isFavorite/${res.data.product_id}`)]).then(result => {
... ...
... ... @@ -1042,7 +1042,7 @@ block-stream@*:
dependencies:
inherits "~2.0.0"
bluebird@3.x.x, bluebird@^3.0.5, bluebird@^3.0.6, bluebird@^3.1.1, bluebird@^3.3, bluebird@^3.4.0, bluebird@^3.4.2, bluebird@^3.5.0:
bluebird@3.x.x, bluebird@^3.0.6, bluebird@^3.1.1, bluebird@^3.3, bluebird@^3.4.0, bluebird@^3.4.2, bluebird@^3.5.0:
version "3.5.0"
resolved "http://npm.yoho.cn/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
... ... @@ -1677,13 +1677,6 @@ concat-stream@~1.5.1:
readable-stream "~2.0.0"
typedarray "~0.0.5"
config-chain@~1.1.5:
version "1.1.11"
resolved "http://npm.yoho.cn/config-chain/-/config-chain-1.1.11.tgz#aba09747dfbe4c3e70e766a6e41586e1859fc6f2"
dependencies:
ini "^1.3.4"
proto-list "~1.2.1"
configstore@^1.0.0:
version "1.4.0"
resolved "http://npm.yoho.cn/configstore/-/configstore-1.4.0.tgz#c35781d0501d268c25c54b8b17f6240e8a4fb021"
... ... @@ -2326,15 +2319,6 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"
editorconfig@^0.13.2:
version "0.13.2"
resolved "http://npm.yoho.cn/editorconfig/-/editorconfig-0.13.2.tgz#8e57926d9ee69ab6cb999f027c2171467acceb35"
dependencies:
bluebird "^3.0.5"
commander "^2.9.0"
lru-cache "^3.2.0"
sigmund "^1.0.1"
ee-first@1.1.1:
version "1.1.1"
resolved "http://npm.yoho.cn/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
... ... @@ -3741,7 +3725,7 @@ inherits@2.0.1:
version "2.0.1"
resolved "http://npm.yoho.cn/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"
ini@^1.3.4, ini@~1.3.0:
ini@~1.3.0:
version "1.3.4"
resolved "http://npm.yoho.cn/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
... ... @@ -4050,15 +4034,6 @@ js-base64@^2.1.8, js-base64@^2.1.9:
version "2.1.9"
resolved "http://npm.yoho.cn/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
js-beautify@^1.6.3:
version "1.6.14"
resolved "http://npm.yoho.cn/js-beautify/-/js-beautify-1.6.14.tgz#d3b8f7322d02b9277d58bd238264c327e58044cd"
dependencies:
config-chain "~1.1.5"
editorconfig "^0.13.2"
mkdirp "~0.5.0"
nopt "~3.0.1"
js-tokens@^3.0.0:
version "3.0.2"
resolved "http://npm.yoho.cn/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
... ... @@ -4587,13 +4562,7 @@ lowercase-keys@^1.0.0:
version "1.0.0"
resolved "http://npm.yoho.cn/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306"
lru-cache@^3.2.0:
version "3.2.0"
resolved "http://npm.yoho.cn/lru-cache/-/lru-cache-3.2.0.tgz#71789b3b7f5399bec8565dda38aa30d2a097efee"
dependencies:
pseudomap "^1.0.1"
lru-cache@^4.0.1:
lru-cache@^4.0.1, lru-cache@^4.1.1:
version "4.1.1"
resolved "http://npm.yoho.cn/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
dependencies:
... ... @@ -5075,7 +5044,7 @@ nodemon@^1.10.2:
undefsafe "0.0.3"
update-notifier "0.5.0"
"nopt@2 || 3", nopt@~3.0.1:
"nopt@2 || 3":
version "3.0.6"
resolved "http://npm.yoho.cn/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
dependencies:
... ... @@ -6278,6 +6247,10 @@ preserve@^0.2.0:
version "0.2.0"
resolved "http://npm.yoho.cn/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@^1.7.0:
version "1.7.0"
resolved "http://npm.yoho.cn/prettier/-/prettier-1.7.0.tgz#47481588f41f7c90f63938feb202ac82554e7150"
prettysize@^0.1.0:
version "0.1.0"
resolved "http://npm.yoho.cn/prettysize/-/prettysize-0.1.0.tgz#38ee534e2d298bc945fb7243203dd873cefc9679"
... ... @@ -6308,10 +6281,6 @@ promise@^7.0.3:
dependencies:
asap "~2.0.3"
proto-list@~1.2.1:
version "1.2.4"
resolved "http://npm.yoho.cn/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
proxy-addr@~1.1.5:
version "1.1.5"
resolved "http://npm.yoho.cn/proxy-addr/-/proxy-addr-1.1.5.tgz#71c0ee3b102de3f202f3b64f608d173fcba1a918"
... ... @@ -6329,7 +6298,7 @@ ps-tree@^1.0.1:
dependencies:
event-stream "~3.3.0"
pseudomap@^1.0.1, pseudomap@^1.0.2:
pseudomap@^1.0.2:
version "1.0.2"
resolved "http://npm.yoho.cn/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
... ... @@ -6910,11 +6879,11 @@ rx-lite@^3.1.2:
version "3.1.2"
resolved "http://npm.yoho.cn/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"
safe-buffer@5.0.1, safe-buffer@^5.0.1, safe-buffer@~5.0.1:
safe-buffer@5.0.1, safe-buffer@~5.0.1:
version "5.0.1"
resolved "http://npm.yoho.cn/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"
safe-buffer@5.1.1, safe-buffer@^5.1.0, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "http://npm.yoho.cn/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
... ... @@ -7113,10 +7082,6 @@ shimmer@^1.1.0:
version "1.1.0"
resolved "http://npm.yoho.cn/shimmer/-/shimmer-1.1.0.tgz#97d7377137ffbbab425522e429fe0aa89a488b35"
sigmund@^1.0.1:
version "1.0.1"
resolved "http://npm.yoho.cn/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
signal-exit@^3.0.0:
version "3.0.2"
resolved "http://npm.yoho.cn/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
... ... @@ -8128,18 +8093,18 @@ vue-lazyload@^1.0.6:
version "1.0.6"
resolved "http://npm.yoho.cn/vue-lazyload/-/vue-lazyload-1.0.6.tgz#7d5494fc35c35fc84dcc271165b827e309b4e793"
vue-loader@^13.0.2:
version "13.0.2"
resolved "http://npm.yoho.cn/vue-loader/-/vue-loader-13.0.2.tgz#78c3e80f69c0520f99a092854dd7d63e3921a28d"
vue-loader@^13.0.5:
version "13.0.5"
resolved "http://npm.yoho.cn/vue-loader/-/vue-loader-13.0.5.tgz#3639e9fb3940cded7f0fc34429277fb6de70a57c"
dependencies:
consolidate "^0.14.0"
hash-sum "^1.0.2"
js-beautify "^1.6.3"
loader-utils "^1.1.0"
lru-cache "^4.0.1"
postcss "^6.0.1"
lru-cache "^4.1.1"
postcss "^6.0.6"
postcss-load-config "^1.1.0"
postcss-selector-parser "^2.0.0"
prettier "^1.7.0"
resolve "^1.3.3"
source-map "^0.5.6"
vue-hot-reload-api "^2.1.0"
... ... @@ -8160,9 +8125,9 @@ vue-router@^2.7.0:
version "2.7.0"
resolved "http://npm.yoho.cn/vue-router/-/vue-router-2.7.0.tgz#16d424493aa51c3c8cce8b7c7210ea4c3a89aff1"
vue-server-renderer@^2.4.2:
version "2.4.2"
resolved "http://npm.yoho.cn/vue-server-renderer/-/vue-server-renderer-2.4.2.tgz#0ba0f984181ea1c455362b09bddf60bc0e0a03fa"
vue-server-renderer@^2.4.4:
version "2.4.4"
resolved "http://npm.yoho.cn/vue-server-renderer/-/vue-server-renderer-2.4.4.tgz#bd59cf4e42dfaf2c9e388af8837b5420dd51360d"
dependencies:
chalk "^1.1.3"
hash-sum "^1.0.2"
... ... @@ -8173,9 +8138,9 @@ vue-server-renderer@^2.4.2:
serialize-javascript "^1.3.0"
source-map "0.5.6"
vue-style-loader@^3.0.0, vue-style-loader@^3.0.1:
version "3.0.1"
resolved "http://npm.yoho.cn/vue-style-loader/-/vue-style-loader-3.0.1.tgz#c8b639bb2f24baf9d78274dc17e4f264c1deda08"
vue-style-loader@^3.0.0, vue-style-loader@^3.0.3:
version "3.0.3"
resolved "http://npm.yoho.cn/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"
dependencies:
hash-sum "^1.0.2"
loader-utils "^1.0.2"
... ... @@ -8192,9 +8157,9 @@ vue-swipe@^2.0.3:
dependencies:
wind-dom "0.0.3"
vue-template-compiler@^2.4.2:
version "2.4.2"
resolved "http://npm.yoho.cn/vue-template-compiler/-/vue-template-compiler-2.4.2.tgz#5a45d843f148b098f6c1d1e35ac20c4956d30ad1"
vue-template-compiler@^2.4.4:
version "2.4.4"
resolved "http://npm.yoho.cn/vue-template-compiler/-/vue-template-compiler-2.4.4.tgz#2cde3b704124985c27d50b5387c9691ba515fb57"
dependencies:
de-indent "^1.0.2"
he "^1.1.0"
... ... @@ -8216,9 +8181,9 @@ vue-touch@2.0.0-beta.3:
rollup-plugin-commonjs "^7.0.0"
rollup-plugin-node-resolve "^2.0.0"
vue@^2.4.2:
version "2.4.2"
resolved "http://npm.yoho.cn/vue/-/vue-2.4.2.tgz#a9855261f191c978cc0dc1150531b8d08149b58c"
vue@^2.4.4:
version "2.4.4"
resolved "http://npm.yoho.cn/vue/-/vue-2.4.4.tgz#ea9550b96a71465fd2b8b17b61673b3561861789"
vuex@^2.4.0:
version "2.4.0"
... ...