NanoTwitter is a ruby app with basic function of twitter. You can follow other users, tweet, like tweets and so on.
Portfolio
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.
We build this web application step by step with frequent integration of code using Github, Codeship, Heroku.
- Design the overall functionality and database(We use PostgreSQL) schema.
- Build the simple skeleton of a Sinatra application.
- Design APIs that have the fundamental interaction with our database.
- We use ActiveRecord to abstract database, which is a great tool implementing ORM(object-relation mapping).
- Build some mini-tests and create test interface.
- Create UI with erb (embedded ruby) and use JQuery to control some behavior of the website elements.
- Include some CDN to beautify the website, such as Bootstrap.
- Using Redis(a cache) to speed up the response by reducing direct database operations.
- Using RabbitMQ(queue, RPC) to communicate between different servers.
- We can pop up the single tweet when you click on this tweet, which is implemented by JQuery.
- We have another Sinatra application running on Heroku that works as a web service for notification.
- 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.
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.
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
- Ruby
- Sinatra
- Activerecord
- PostgreSQL
- Javascript
- JQuery
- Bootstrap
- Bootbox
- Rake
- Redis
- RabbitMQ
- Resque
- Rack
- ...
-
0-1000 over 1 min with the root url not logged in
- Max # of clients active:1000
- What time stopped:1min
- average response time (ms):2503
- min/max response times:15/7151
- Error Rate:0%
- total successes (response counts):11137
-
0 - 500 in 1 min Logged In (Test 2) - User14, Verda
- Max # of clients active:500
- What time stopped:1min
- average response time (ms):1987
- min/max response times:12/4842
- Error Rate:0%
- total successes (response counts):6987
-
Logged in Random Tweets (Test 3) 0-500 clients over 1 min
- Max # of clients active:500
- What time stopped:1min
- average response time (ms):3353
- min/max response times:17/7750
- Error Rate:0%
- total successes (response counts):4011
- random send tweet:"Hello,bonnie"
-
All complete! Cheers!
nT1.0
This project is licensed under MIT License
Thanks for Professor Pito Salas's great guide and help from teaching assistants Karishma Reddy Khan and Alex Suk.
- To run the test, conduct
rake db:test:prepare
andrake db:test:load
Then typerake
in the terminal to run all the test - Reset database:
heroku pg:reset DATABASE_URL
- We must flush all redis after test api used, and restart app.
run
heroku redis:cli
flushall
heroku run rake db:migrate
lsof -i :4567
to see which process is running in port 4567- https://nano-notification.herokuapp.com/start will start the rabbitmq notification service
- git clone
- install redis in local and run redis by
redis-server
links: http://download.redis.io/releases/redis-3.2.5.tar.gz follow readme to install redis first - install RabbitMQ server by
brew update
,brew install rabbitmq
, should first install brew first. Run rabbitmq byrabbitmq-server
if you have some problem to start, trysudo chown $(whoami) /usr/local/share/man/man3
andsudo chown $(whoami) /usr/local/share/man/man5
- install all gems by
bundle install
- install PostgreSQL and open it
- run
rake db:migrate
- run
ruby app.rb
to start the service - open
0.0.0.0:4567
in the web browser - reset data using test api
- done!
Dec 8, 2016