测试nginx网站代码_在40行以下代码中使用NGINX进行A / B测试
测试nginx网站代码
by Nitish Phanse
由Nitish Phanse
在40行以下代码中使用NGINX进行A / B测试 (A/B testing with NGINX in under 40 lines of code)
A/B Testing, has enabled designers and product managers to get a deep insight into user behavioral patterns.
A / B测试使设计师和产品经理可以深入了解用户的行为模式。
On the one hand, it has allowed product managers more flexibility while conceptualizing user journeys. But on the other, it’s become a developer’s nightmare, being told to make two versions of the same component.
一方面,它使产品经理在概念化用户旅程的同时具有更大的灵活性。 但另一方面,它被告知要制作同一组件的两个版本,这已成为开发人员的噩梦。
“The general concept behind A/B testing is to create an experiment with a control group and one or more experimental groups (called “cells” within Netflix) which receive alternative treatments. Each member belongs exclusively to one cell within a given experiment, with one of the cells always designated the “default cell”. This cell represents the control group, which receives the same experience as all Netflix members not in the test.”
“ A / B测试背后的一般概念是与对照组和一个或多个接受替代治疗的实验组(在Netflix中称为“细胞”)建立实验。 每个成员在给定实验中仅属于一个单元,其中一个单元始终指定为“默认单元”。 这个单元代表对照组,与未参加测试的所有Netflix成员一样,他们将获得相同的体验。”
- Netflix blog
-Netflix博客
当前的生态系统能提供什么? (What does the present ecosystem offer?)
A lot of companies like Mixpanel, VWO, and Optimisely provide client SDKs (JavaScript code) which have to be added in the head
tag of the page HTML. The tests can then be created via a dashboard.
很多公司(例如Mixpanel,VWO和Optimizely)都提供了客户端SDK(JavaScript代码),这些必须添加到页面HTML的head
标签中。 然后可以通过仪表板创建测试。
Although the above methods give you a lot of options when it comes to button colors, component height, and other CSS attributes, it doesn’t really allow you to create two separate flows altogether.
尽管上述方法在按钮颜色,组件高度和其他CSS属性方面为您提供了很多选择,但实际上并不允许您完全创建两个单独的流程。
Also, some external libraries can really hamper your page load times and can create a jittery/laggy experience for users.
此外,某些外部库确实会妨碍您的页面加载时间,并可能给用户带来不安/缓慢的体验。
介绍NGINX (Presenting NGINX)
Nginx is a light web server that offers a bunch of functionality like load balancing, reverse proxying, and HTML compression. It’s easy to setup and really offers a lot of control to developers.
Nginx是一个轻量级的Web服务器,提供了很多功能,例如负载平衡,反向代理和HTML压缩。 它易于设置,确实为开发人员提供了很多控制。
NGINX is a terrific tool for distributing traffic for split tests.
NGINX是用于分配流量以进行拆分测试的绝佳工具。
It’s stable, it’s blazingly fast, and configurations for typical use cases are prevalent online. More complex configuration can be accomplished after just a couple hours exploring the documentation. Small companies may not have resources to spend on paid software for A/B testing, but NGINX provides an option to carry out some form of A/B testing.
它稳定,速度极快,典型用例的配置在网上很普遍。 在浏览文档仅几个小时之后,即可完成更复杂的配置。 小型公司可能没有资源来购买用于A / B测试的付费软件,但是NGINX提供了进行某种形式的A / B测试的选项。
For example, say you want to see which of the forms below will have better conversion:
举例来说,假设您想查看下列哪种表格的转换效果更好:
Your hypothesis might be that fewer form fields imply less data being inputted by the user, thus leading to more conversions.
您的假设可能是更少的表单字段意味着用户输入的数据更少,从而导致更多的转换。
So we can define two buckets: Version A and Version B. The former is the control group, which is shown to 80% of the traffic. The latter is the test group, which forms the remaining 20% of the traffic.
因此,我们可以定义两个存储桶:版本A 和版本B。前者是对照组,显示为80%的流量。 后者是测试组,占剩余流量的20%。
Port 7770 will host one bucket of the code, whereas port 7777 will host the second bucket of the code.
端口7770将托管代码的一个存储桶,而端口7777将托管代码的第二个存储桶。
码 (Code)
Your nginx.conf file can be modified as shown below.
您的nginx.conf文件可以如下所示进行修改。
http { # ... # application version 1a upstream version_a { server server 127.0.0.1:7770; ## Can be an external ip too }
# application version 1b upstream version_b { server server 127.0.0.1:7777; ## Can be an external ip too }
split_clients "app${remote_addr}${http_user_agent}${date_gmt}" $appversion { 80% version_1a; * version_1b; }
server { # ... listen 80; location / { proxy_set_header Host $host; proxy_pass http://$appversion; } }}
Create two upstreams, one for each bucket.
创建两个上游,每个存储桶一个。
The split_client
directive helps us divert traffic along with the specified weightage to a particular upstream.
split_client
指令可帮助我们将流量和指定的权重转移到特定的上游。
The app${remote_addr}${http_user_agent}${date_gmt}appversion
creates a hash based on the above parameters and is used by nginx to log a request made to either bucket. Preferably these parameters are those which are pertaining solely to a user, like user_agent
, remote addr
.
app${remote_addr}${http_user_agent}${date_gmt}appversion
根据上述参数创建一个哈希,nginx使用该哈希记录对任一存储桶发出的请求。 优选地,这些参数是仅与用户有关的那些参数,例如user_agent
, remote addr
。
Ok — so this will work, but it doesn’t give the user a persistent experience.
好的-这样就可以了,但是并不能给用户持久的体验。
If I refresh my page, there is a chance I’ll switch between buckets, and this can be a horrid user experience.
如果刷新页面,则有可能在存储桶之间切换,这可能会带来可怕的用户体验。
Consider the above case: imagine trying to fill a six field form, and then suddenly, on refreshing, seeing a two field form. Confusing!
考虑上面的情况:假设尝试填写一个六字段表单,然后在刷新时突然看到一个两字段表单。 令人困惑!
不同的方法 (A different approach)
- Proxy pass request to either bucket代理通过请求到任一存储桶
- Set a cookie with an expiration time equal to duration of test.设置cookie的有效时间等于测试持续时间。
- Check for cookie existence and proxy pass to correct bucket to ensure a uniform user experience.检查cookie的存在和代理传递以更正存储桶,以确保统一的用户体验。
We will use NGINX’s map
directive and map the $cookie_name
variable to different buckets that we have created.
我们将使用NGINX的map
指令并映射$cookie_name
变量以创建不同的存储桶。
http { # ... # application version a upstream version_a { server server 127.0.0.1:7770; ## Can be an external ip too }
# application version b upstream version_b { server server 127.0.0.1:7777; ## Can be an external ip too } split_clients "app${remote_addr}${http_user_agent}${date_gmt}" $appversion { 80% version_a; * version_b; }
map $cookie_split_test_version $upstream_group { default $appversion; "version_a" "version_a"; "version_b" "version_b"; }
server { # ... listen 80; location / { add_header Set-Cookie "split_test_version=$upstream_group;Path=/;Max-Age=518400;";
proxy_set_header Host $host;
if ($upstream_group = "version_a") { proxy_pass http://127.0.0.1:7777; break; }
if ($upstream_group = "version_b") { proxy_pass http://127.0.0.1:7770; break; }
proxy_pass http://$appversion; } }}
As it’s a little hard to format the above code…
由于格式化上面的代码有点困难……
结论 (Conclusion)
- NGINX provides a very simple API to create an A/B test environment.NGINX提供了一个非常简单的API来创建A / B测试环境。
- Allows for multiple buckets to be created. The example above shows two buckets, but we can split traffic and create more buckets.允许创建多个存储桶。 上面的示例显示了两个存储桶,但我们可以拆分流量并创建更多存储桶。
- As the same code is hosted on two ports, deployment can become tricky (presently I have two branches: a master and a test branch), whether done off a different branch or from the same one.由于将相同的代码托管在两个端口上,因此部署可能会变得很棘手(目前我有两个分支:一个主分支和一个测试分支),无论是在其他分支上进行还是从同一分支进行。
Carrying more than one A/B test can become tricky. Yes, you can use the
location
directive and set different cookies based on the required tests, but having two tests (Test 1, Control: 80, Test 20 & Test 2 Control: 50, Test 50) is impossible. That said, you should not have more than one A/B test at a time per page. Otherwise you will end up having 2^n versions of your page, where n is the number of tests, and tracking conversions will be hell.进行多个A / B测试可能会很棘手。 是的,您可以使用
location
指令并根据所需的测试设置不同的cookie,但是不可能有两个测试( Test 1,Control:80,Test 20&Test 2 Control:50,Test 50 )。 就是说,您每页一次不能进行多个A / B测试。 否则,您最终将拥有2 ^ n个页面版本,其中n是测试数量,并且跟踪转换将是地狱。- Tracking can now be done at a very granular level as the code bases are effectively separate.由于代码库是有效分离的,因此现在可以在非常精细的级别上进行跟踪。
Do let me know if I’ve made any mistake in the above. Happy to correct and learn. Hope you liked the article.
如果我在上面有任何错误,请告诉我。 乐于纠正和学习。 希望您喜欢这篇文章。
PS: Did anyone notice it is less than 40 lines of code?!
PS:有没有人注意到它少于40行代码?
翻译自: https://www.freecodecamp.org/news/a-b-testing-with-nginx-in-40-lines-of-code-d4f94397130a/
测试nginx网站代码
相关文章:

HttpServletResponse,HttpServletRequest详解
HttpServletResponse,HttpServletRequest详解 1、相关的接口 HttpServletRequest HttpServletRequest接口最常用的方法就是获得请求中的参数,这些参数一般是客户端表单中的数据。同时,HttpServletRequest接口可以获取由客户端传送的名称,也可…

[微信小程序]this.setData , that.setData , this.data.val三者之间的区别和作用
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 1.this.setData({ }) <view bindtouchmove"tap_drag" bindtouchend"tap_end" bindtouchstart"tap_start" class"page-top" style"{…

jQuery(一)引入
一、jQuery简介 jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多) 二、安装 2.1、下载 下载地址:http://jquery.com/download/ 2.2、引入 在页面头部加入 <head> <meta http-equiv"Content-Type&…

javascript 堆栈_JavaScript调用堆栈-它是什么以及为什么它是必需的
javascript 堆栈The JavaScript engine (which is found in a hosting environment like the browser), is a single-threaded interpreter comprising of a heap and a single call stack. The browser provides web APIs like the DOM, AJAX, and Timers.JavaScript引擎(可在…

idea崩溃导致的svn插件丢失问题, maven dependencies视图丢失问题
Idea丢失Svn解决办法今天打开Idea,习惯用ctrlt来更新svn,杯具出现了,快捷键失效了,我觉得可能是其他的什么软件占用了这个快捷键,于是重启了一下,发现还是不行,svn信息怎么没了,chan…

python3代码
import urllib.request url"http://mm.taobao.com/json/request_top_list.htm?type0&page1" upurllib.request.urlopen(url)#打开目标页面,存入变量up contup.read()#从up中读入该HTML文件 key1<a href"http#设置关键字1key2"target&qu…

【微信小程序】侧滑栏,手动侧滑出个人中心(完整代码附效果图)
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: 博文分三部分,1.效果图及功能效果说明 2.实现思路 3.源代码 欢迎加入微信小程序开发交流群(173683895) 一.老惯例先上效果图,本篇博…

1:1 人脸比对 开源_Hacktoberfest:我的开源门户
1:1 人脸比对 开源by Maribel Duran通过Maribel Duran Hacktoberfest:我的开源门户 (Hacktoberfest: My Gateway to Open Source) “Individually, we are one drop. Together, we are an ocean.”“就个人而言,我们只是一滴滴。 在一起,我们…

地图收敛心得170405
寻路算法大总结! 交换机生成树采用的是完全不同的D-V(distance vector)距离矢量算法,并不是很可靠. 并不是任意两点之间的最短路径,因为任意两点之间取最短路径可能有环路:总权更大 交换机STP不一定是最小生成树!!!举例论证 因为它只是所有交换机到根桥最短 贪心算法的味道 kru…

微信小程序游戏开发文档以及开发工具地址
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文: 微信官方于 2017 - 12 - 28 日 开发微信小程序 开发小游戏 , 微信小程序小游戏开发官方文档的地址 https://mp.weixin.qq.com/debug/wxagame/dev/index.html?t20171228…

c#编译执行过程
创建一个简单的控制台程序,源码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace csharpBuildProcess {class Program{static void Main(string[] args){for (int i 0; i < 100; i){if(i%20)…

渐进式web应用程序_渐进式Web应用程序简介
渐进式web应用程序Interested in learning JavaScript? Get my ebook at jshandbook.com有兴趣学习JavaScript吗? 在jshandbook.com上获取我的电子书 Progressive Web Apps (PWA) are the latest trend in mobile application development using web technologies.…

第二百二十节,jQuery EasyUI,Slider(滑动条)组件
jQuery EasyUI,Slider(滑动条)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Slider(滑动条)组件的使用方法,这个组件依赖于 Draggable(拖动)组件。 一.加载方式 class 加载方式 <…

适用于SharePoint 2013 的 CAML Desinger
适用于SharePoint 2013 的 CAML Desinger 分类: SharePoint2013-01-15 21:52 1877人阅读 评论(0) 收藏 举报CAMLDesingerSharePoint 2013代码生成适用于如果说Sql是信息管理系统的一等公民,那么SharePoint 系统中的一等公民就非CAML莫属了。 但是这个一等…

微信小程序 跑马灯效果完整代码附效果图
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 一:功能介绍及讲解 实现的跑马灯(跑马灯里面显示文章的title)的效果,并在右侧有个查看文章的按钮,按钮绑定当前的跑马灯信…

热闹的聚会与尴尬的聚会_如何增加(和保存)您最喜欢的技术聚会
热闹的聚会与尴尬的聚会by Jen Weber詹韦伯(Jen Weber) 如何增加(和保存)您最喜欢的技术聚会 (How to Grow (and Save) Your Favorite Tech Meetup) Hey meetup facilitators, friends, and future leaders! Do you want more people to show up to your tech event? Or at l…

蓝桥杯-搭积木-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: 蓝桥杯赛题 * 作 者: 彭俊豪 * 完成日期…

微信小程序多张图片和表单一起上传,验证表单及进度条的实现完整代码
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 效果图: 完整代码: <!--pages/register/register.wxml--> <view classtop> <view>注 册 须 知 : </view> </view> <view> <view …

Android, BaseAdapter 处理大数据量时的优化
Android优化 最常见的就是ListView, Gallery, GridView, ViewPager 的大数据优化 图片优化 访问网络的优化优化的原则: 数据延迟加载 分批加载 本地缓存数据优化 1).复用contentview 2).创建static class ViewHolder 3).分…

meetup_我在2017年举办Meetup中学到的知识以及为何对2018年充满期待。
meetupby Daniel Deutsch由Daniel Deutsch 我在2017年举办Meetup中学到的知识以及为何对2018年充满期待。 (What I’ve learned hosting Meetups in 2017 — and why I’m looking forward to 2018.) As 2017 comes to an end, it’s time to reflect on the non-profit work …

BASE64 编码和解码
依赖jar: import org.apache.commons.codec.binary.Base64; BASE64和其他相似的编码算法通常用于转换二进制数据为文本数据,其目的是为了简化存储或传输。更具体地说,BASE64算法主要用于转换二进 制数据为ASCII字符串格式。Java语言提供了一个非常好的BA…

Android开发常用属性
1、android string.xml 文字中间加入空格 android string.xml前后加空格的技巧 <string name"password">密 码</string>   这个就代表着空格 2、文字单行显示 android layout布局文件中TextView、EditView单行显示和输入 <TextView androi…

JS计算起点坐标到终点坐标的驾车距离和驾车时间
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 先上计算距离的简单demo: <!DOCTYPE html> <html><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8"&…

css flexbox模型_5分钟内学习CSS Flexbox-初学者教程
css flexbox模型快速介绍流行的布局模块 (A quick introduction to the popular layout module) In this post, you’ll learn the basics of CSS Flexbox, which has become a must-have skill for web developers and designers in the last couple of years.在本文中&#x…

「linux网络管理」OSI模型
学习linux网络管理,笔记整理,促进记忆。 OSI(开放系统互联模型)包含七层,由应用层向物理层递进,分别有不同的协议和数据处理方式。 应用层--> 表示层--> 会话层--> 传输层--> 网络层--> 数据…

微信小程序下拉刷新和上拉加载的实现
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 一: 下拉刷新 下拉刷新两个步骤就能实现。 1.在要实现下拉刷新的页面的json配置文件里面加上 "enablePullDownRefresh": true, //开启下拉刷新"backgro…

Spring整合Hibernate的步骤
为什么要整合Hibernate?1、使用Spring的IOC功能管理SessionFactory对象 LocalSessionFactoryBean2、使用Spring管理Session对象 HibernateTemplate3、使用Spring的功能实现声明式的事务管理 整合Hibernate的步骤:1、配置SessionFactory(能够…

初创企业购买企业邮箱_支持#NetNeutrality =支持设计师及其创建的初创企业
初创企业购买企业邮箱by Lukasz Lysakowski卢卡斯吕萨科夫斯基(Lukasz Lysakowski) 支持#NetNeutrality 支持设计师及其创建的初创企业 (Supporting #NetNeutrality Supporting Designers and the Startups They Create) I believe in Net Neutrality, and I wrote a brief e…

【转】Android source build/envsetup.sh学习笔记
原文网址:http://blog.csdn.net/mliubing2532/article/details/7567164 如果你只需要修改某一个模块的内容,但是却每次都要执行make, 最后等待很长时间。使用模块编译,那只需要在你所在的模块的目录或者其子目录,执行mm࿰…

微信小程序之上传附件
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 目前微信API开放上传图片,录音文件,视频文件,but 只能下载并打开附件,不能上传附件,以后会不会开放附件上传目前还不确定&…