Giter Site home page Giter Site logo

bop2016-semifinal's Introduction

BOP2016-semifinal

简介

队伍:蛋黄麻薯 排名:4

方法

  1. 使用 requests 的 session 让HTTP请求Keep-Alive
  2. 利用Or方法把多条查询合并为一次查询,超过长度则并行查询
  3. 在测试中我们发现使用一种方案并不能保证一直是最快的。所以,我们考虑关键路径使用两种方案并行,返回最快的一个结果。 如paper-paper-paper-paper,可以有两种方案:正向和反向同时查,中间取交集;完全正向并行查。
  4. 并行部分使用了 concurrent.futures 的线程池。
  5. 关于cache。我们最终部署没有开启cache,因为担心在测试前数据会变,cache失效。

小结

这次题目的关键是优化网络的响应速度。因为网络IO的时间高达60~1000ms,所以CPU计算的时间几乎可以忽略。 使用python可以快速开发,语言并没有太大影响。 我们优化网络IO的总体思路是将查询并行、减少查询数,这样并行的查询的的速度就只跟最慢的查询有关。 最后再着重优化最慢的查询,采用多种方案同时计算,返回最快的一个可以有效避免慢查询。 另外,用更快的http库也能优化时间,但是我们在这方面做得不够好。 最终排名4。

环境

  • python 2.7
  • tornado 4.3
  • requests 2.9.1

运行

执行python http_server.py启动服务器。 默认监听80端口。

bop2016-semifinal's People

Contributors

visionthinking avatar

Watchers

James Cloos avatar LiLang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.