Skip to content

A baby version of Twitter designed as a platform for experimentation with scaling issues

Notifications You must be signed in to change notification settings

Dragoncell/nanotwitter

 
 

Repository files navigation

NanoTwitter Code Climate

NanoTwitter is a ruby app with basic function of twitter. You can follow other users, tweet, like tweets and so on.
Portfolio

Authors

Summary Statement

This project is a web application with the basic function of twitter. A logged in user can tweet, follow and unfollow other users, like and unlike tweet. A user can see all the tweets of his/her followings in the timeline.

We provide RESTful apis, which send reponses in json. We also provide a client library which send and process http request to our apis.

We optimize our application to handle large scalability problems. Techniques we used including cache, multiple threads, queue, seperate service.

Technology Description

We build this web application step by step with frequent integration of code using Github, Codeship, Heroku.

  1. Design the overall functionality and database(We use PostgreSQL) schema.
  2. Build the simple skeleton of a Sinatra application.
  3. Design APIs that have the fundamental interaction with our database.
  4. We use ActiveRecord to abstract database, which is a great tool implementing ORM(object-relation mapping).
  5. Build some mini-tests and create test interface.
  6. Create UI with erb (embedded ruby) and use JQuery to control some behavior of the website elements.
  7. Include some CDN to beautify the website, such as Bootstrap.
  8. Using Redis(a cache) to speed up the response by reducing direct database operations.
  9. Using RabbitMQ(queue, RPC) to communicate between different servers.

Interesting Engineering

  1. We can pop up the single tweet when you click on this tweet, which is implemented by JQuery.
  2. We have another Sinatra application running on Heroku that works as a web service for notification.
  3. We have a special function that the app will recommend some users may interest to current user realized by shuffle. shuffle(arr, k) is an interesting method that input an array and a number k. Then it will return k random elements without repetition.

Getting Started

Notification service repo: https://github.com/FrankYan93/nanoNotification
We must visit https://nano-notification.herokuapp.com/start to start our web service for notification.
Main website: https://nano-twitter-dratini.herokuapp.com
You are welcome to sign up and have fun.

Running the tests

How to run tests

rake (run all minitests)
ruby test/testUser/testGet.rb
ruby test/testUser/testUserCreate.rb
ruby test/testUser/testFollowUnfollow.rb
ruby test/testUser/testEditProfile.rb
ruby test/testTweet/testTweetCreate.rb

Screenshots

  • Click the awesome image to see our descriptive video.[If you are curious about our voice :) ] nanoTwitter

Built with

  • Ruby
  • Sinatra
  • Activerecord
  • PostgreSQL
  • Javascript
  • JQuery
  • Bootstrap
  • Bootbox
  • Rake
  • Redis
  • RabbitMQ
  • Resque
  • Rack
  • ...

Loader Test Results

  • 0-1000 over 1 min with the root url not logged in

    1. Max # of clients active:1000
    2. What time stopped:1min
    3. average response time (ms):2503
    4. min/max response times:15/7151
    5. Error Rate:0%
    6. total successes (response counts):11137
  • 0 - 500 in 1 min Logged In (Test 2) - User14, Verda

    1. Max # of clients active:500
    2. What time stopped:1min
    3. average response time (ms):1987
    4. min/max response times:12/4842
    5. Error Rate:0%
    6. total successes (response counts):6987
  • Logged in Random Tweets (Test 3) 0-500 clients over 1 min

    1. Max # of clients active:500
    2. What time stopped:1min
    3. average response time (ms):3353
    4. min/max response times:17/7750
    5. Error Rate:0%
    6. total successes (response counts):4011
    7. random send tweet:"Hello,bonnie"
  • All complete! Cheers!

  • Result Of Scalability Work Result Of Scalability Work

Version

nT1.0

License

This project is licensed under MIT License

Acknowledgments

Thanks for Professor Pito Salas's great guide and help from teaching assistants Karishma Reddy Khan and Alex Suk.

Tips

  1. To run the test, conduct rake db:test:prepare and rake db:test:load Then type rake in the terminal to run all the test
  2. Reset database: heroku pg:reset DATABASE_URL
  3. We must flush all redis after test api used, and restart app. run heroku redis:cli flushall
  4. heroku run rake db:migrate
  5. lsof -i :4567 to see which process is running in port 4567
  6. https://nano-notification.herokuapp.com/start will start the rabbitmq notification service

Steps in local:

  1. git clone
  2. install redis in local and run redis by redis-server links: http:https://download.redis.io/releases/redis-3.2.5.tar.gz follow readme to install redis first
  3. install RabbitMQ server by brew update, brew install rabbitmq, should first install brew first. Run rabbitmq by rabbitmq-server if you have some problem to start, try sudo chown $(whoami) /usr/local/share/man/man3 and sudo chown $(whoami) /usr/local/share/man/man5
  4. install all gems by bundle install
  5. install PostgreSQL and open it
  6. run rake db:migrate
  7. run ruby app.rb to start the service
  8. open 0.0.0.0:4567 in the web browser
  9. reset data using test api
  10. done!

Last Modify Date

Dec 8, 2016

About

A baby version of Twitter designed as a platform for experimentation with scaling issues

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 62.5%
  • HTML 37.5%